[English]
Hello hive, this time I want to tell you about the login I added to be able to use it in my game.
We are custom to seeing logins in the vast majority of applications we use every day, without realizing all the work behind this valuable component, which has the purpose that only those who have the correct credentials (username and password) are authorized to login to the application.
https://hive.blog/ - login
How a login works in broad strokes
Basically the flow of user authorization and authentication through login happens in the following sequence.
The user enters their username and password and sends it from the login form to the application server.
The server receives the request, if the user and passwords are valid then it will generate a session, a token or some other authentication method.
The server returns a message or token to the client indicating whether or not the operation was successful, if not successful, it will indicate the reasons and what should be done in such a case.
Now each request made by the client to the server would be checked to verify that it is secure, and therefore, the server would authorize access to the requested resource.
Example token base authentication
Authentication of applications is a very important issue, because it is the first layer of security that your application will have and the way you build it will determine how secure it will be.
I also want to mention that I am actually making a website that will contain the game I am making, which means the login is not only for a single game, but all web site and the futures games.
Choosing an Authentication type for REST API
There are various authentication methods out there such as session based authentication, Oauth 2.0, OpenID Connect etc. I had to choose the most suitable one for my REST API, in my case I chose a token-based authentication, because it is easier to implement in my application, although it is not less secure in its execution.
Also known bearer authentication can be understood as giving the bearer access to this token. The token or key is a chain of encrypted characters that allow access to a certain resource or URL. The client should send this token in the authorization header every time he makes a request to protected resources in the server, which will validate the access.
Some of the advantages of token-based authentication are
- Stateless, scalable, and decoupled.
The server does not store any type of token data, however, in every request between the client and the server, communication is never lost.
- Performance
Not storing any customer authentication data reduces the load on the server considerably.
- Multi-platform
A well configured REST API with token-based authentication can serve any type of application, be it mobile, web or desktop.
All this was pure theory so far. Was it very confusing? 馃槄 The truth is that it is a very complex but interesting topic, there is a lot of information on the internet, if you are interested do not stop investigating about it or comment your doubts and we can discuss it.
My implementation
In my experience, there is no one way to implement something, it all depends on what the project needs.
In my case I my Backend or API that resolves requests from my website. I use JWT to generate and decode the client tokens and mongodb to store the registered users.
On my website or Frontend I use Angular Framework, there I have some components as interceptors to catch http requests and add them the token header and JWT on the client side, to decode the token received by the server and know what information to show to each user who accessed the site.
The result
I Forget say that even before you can do a login you need to do a user registration on the website, for that we need a sign up page, once the user with their encrypted password are registered in the database already the login will be the next step.
Conclusion
It was necessary to do the login module in the application before even making the game, in order to be able to store data from the game itself, even if it was in test mode in a database, it would hepl a lot of the game development.
There were many challenges and problems I had to face and I did not mention in this post, but in the end it could be solved without major problem.
All this had to be done just like that in order to request a login at the start of the game. 馃榿
Thanks for stopping by.
[Espa帽ol]
Hola hive, esta vez quiero contarles acerca del inicio de sesi贸n que a帽ad铆 para poder utilizarlo en mi juego.
Estamos acostumbrados a ver inicios de sesi贸n en la gran mayor铆a de aplicaciones que usamos cada d铆a, sin percatarnos de todo el trabajo que hay detr谩s de este valioso componente, el cual tiene como prop贸sito que solo quien tiene las credenciales (usuario y contrase帽a) correctas est茅n autorizados a entrar a la aplicaci贸n en cuesti贸n.
https://hive.blog/ - login
Como funciona un inicio de sesi贸n a grandes rasgos.
B谩sicamente el flujo del autorizaci贸n y autenticaci贸n del usuario a trav茅s del inicio de sesi贸n sucede en la siguiente secuencia.
El usuario escribe su usuario y contrase帽a y lo env铆a desde el formulario del inicio de sesi贸n al servidor de la aplicaci贸n.
El servidor recibe la solicitud, si el usuario y contrase帽as son v谩lidos entonces generar谩 una sesi贸n, un token o alg煤n otro m茅todo de autenticaci贸n.
El servidor devuelve un mensaje o un token al cliente indicando si fue o no exitosa la operaci贸n, de no ser exitosa, indicara los motivos y que debe hacerse en tal caso.
A partir de aqu铆 cada petici贸n que haga el cliente al servidor se comprobar铆a para verificar que es segura, y, por tanto, el servidor autorizar铆a el acceso al recurso solicitado.
Ejemplo de autenticaci贸n por token
La autenticaci贸n de las aplicaciones es una cuesti贸n muy importante, porque es la primer capa de seguridad que tendr谩 tu aplicaci贸n y la manera que la construyes determinara que tan segura ser谩.
Quiero mencionar tambien que en realidad estoy haciendo un sitio web que contendr谩 el juego que estoy haciendo, y posteriormente otros juegos, lo que significa que el inicio de sesi贸n no es 煤nicamente para este juego.
Escogiendo un tipo de Autenticaci贸n para REST API
Hay varios m茅todos de autenticaci贸n ahi afuera como lo son; Autenticaci贸n por secciones Oauth 2.0, OpenID Connect etc. Ten铆a que elegir el m谩s adecuado para un mi API REST, en mi caso eleg铆 una autenticaci贸n basada en tokens, porque es mas f谩cil de implementar en mi aplicaci贸n, aunque no por eso es menos segura en su ejecuci贸n.
Tambi茅n conocida autenticaci贸n de portador puede entenderse como dar acceso al portador de este token. El token o llave es una cadena de car谩cteres encriptados que permiten el acceso a un determinado recurso o URL. El cliente debe enviar este token en el encabezado de autorizaci贸n cada vez que realic茅 solicitudes a recursos protegidos al servidor, el cual validar谩 el acceso.
Algunas ventajas de la autenticaci贸n por token son:
- Sin estado, escalable y desacoplado.
El servidor no guarda ning煤n tipo de dato del token, sin en cambio en cada petici贸n entre el cliente y el servidor nunca se pierde la comunicaci贸n.
- El rendimiento
Al no almacenar ningun dato de autenicaci贸n del cliente disminuye la carga en el sevidor considerablemente.
- Multiplataforma
Una API REST bien configurada con la autenticaci贸n basada en tokens puede servir a cualquier tipo aplicaci贸n, ya sea m贸viles, web o escritorio.
Bien todo esto fue pura teor铆a hasta aqu铆. Fue muy confuso? 馃槄 La verdad es que es un tema muy complejo pero interesante, hay mucha informaci贸n en internet, si les interesa no dejen de investigar al respecto o comentar sus dudas y podemos discutirlo.
Mi implementaci贸n
En mi experiencia, no hay una 煤nica manera de implementar algo, todo depende de lo que el proyecto necesite.
En mi caso en mi Backend o API resuelve las peticiones de mi sitio web. Utilizo JWT para generar y decodificar los tokens del cliente y mongodb para almacenar a los usuarios que se vallan registrando al sitio.
En mi sitio web o Frontend uso Angular Framework, ahi tengo algunos componentes como interceptores para atrapar las peticiones http y agregarles a la cabecera el token y JWT del lado del cliente, para decodificar el token recibido por el servidor y saber que informaci贸n mostrar a cada usuario que accedi贸 al sitio.
El resultado
Olvide mencionar que incluso antes de de poder hacer un inicio de sesi贸n se necesita hacer un registro de usuario en el sitio web, para eso necesitamos una pagina de registro, una vez que el usuario con su contrase帽a encriptada est茅n registrados en la base de datos ya se podr谩 hacer el inicio de sesi贸n correctamente.
Conclusi贸n
Era necesario hacer el m贸dulo de inicio de sesi贸n en la aplicaci贸n antes de hacer incluso el juego, para poder ir almacenando datos del juego mismo, aunque fuese en modo de prueba en una base de datos, eso ayudar铆a mucho al desarrollo del juego.
Hubo muchos retos y problemas que tuve que enfrentar que no menciono en esta publicaci贸n, pero al final se pudieron resolver sin mayor problema.
Todo esto tuvo que hacerse as铆 solo para poder pedir un inicio de sesi贸n al inicio del juego. 馃榿
Gracias por visitar mi blog.
Glossary
References
https://blog.restcase.com/4-most-used-rest-api-authentication-methods/
https://www.google.com/amp/s/openwebinars.net/amp/blog/que-es-json-web-token-y-como-funciona/
Older post
Added full screen mode and other features
All graphics resources of the game was taken from
Tools, Libraries, Frameworks
https://www.phaser.io/phaser3
https://socket.io/
https://nodejs.org/en/
https://angular.io/
https://tailwindcss.com/
https://www.mongodb.com/