Danidre

In-Game Login API

Recommended Posts

Newgrounds.io allows anyone to incorporate a login system to their game.

From what I understand, they login to their newgrounds account, directly in the game, and they can even have that game on their own website.

In other words, they do not need to upload the game to newgrounds, yet they can still be authenticated from Newgrounds.

I assume an API is used, but I'm not sure how. If cookies are stored locally, or if JWT Tokens are used.

I have a multiplayer game which works using 2 separate programs:

  • The server is run using Node.JS hosted by Heroku
  • The client is run on a static site hosted by Netlify (it's a single page JS Canvas game)
  • The connection is made possible using Socket.io

 

My problem:

I want the client to be able to click a button (sign in) enter their unsername and password, and submit; thus making a request over to the server, for authentication. There, the server will verify if that information is correct, and grant that user access (which would be used for saving that user's character data or inventory items).

However, how do I handle...authorizing that same user if they refresh the page? How would the server know that that browser is that same computer; that same user. How would that JS static site know to check if it was logged in, or if it needs to log in? Cookies or something?

JWT Tokens rings in my head, but I don't have much knowledge to say for sure if that would work.

Lastly, how would I send the requests to the API? Using a socket.emit? Or should I use a fetch or axios call to the server from the static site? Then that'll lead to questions such as how to allow requests from that one specific static site, because I know of things like CORS that prevents cross...requests (or something of that sort)

 

I would really appreciate if anyone can help in this discussion, and if they can also link to where I can find discord servers or forums that are targeted to these questions. Since it seems to me like there's a silence in information such as these, and I've been researching for months figuring out everything on my own.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.