Gomniauth is a better solution as GoLang OAuth2 package. First we need to install Gomniauth package.
In this demo we will use Google as the authentication provider. Using Google Developer Console you can create a client id and client secrets. And also you have to give host URL and re directional URL. Then will setup Gomniauth in main.go file.
Next will add login.html file.
Add endpoint for login.html in main function.
Next we need to write callback handler. In callback, we can retrieve user's basic data using Gomniauth functions. Once we have response data, we Base64 encode full name and save it into a cookie called auth cookie. Then we can retrieve those details later from the cookie and show it in our web pages.
Update home.html file to show name retrieved from Google login.
No comments:
Post a Comment