![]() ![]() If your goal is to make it easy for users to register with your app or website, then implementing the “Sign in with Google” option should be at the top of your priority list. RefreshTokenExpiresIn time.Users love convenience. RefreshTokenPublicKey string `mapstructure:"REFRESH_TOKEN_PUBLIC_KEY"`ĪccessTokenExpiresIn time.Duration `mapstructure:"ACCESS_TOKEN_EXPIRED_IN"` RefreshTokenPrivateKey string `mapstructure:"REFRESH_TOKEN_PRIVATE_KEY"` PostgresSource string `mapstructure:"POSTGRES_SOURCE"`ĪccessTokenPrivateKey string `mapstructure:"ACCESS_TOKEN_PRIVATE_KEY"`ĪccessTokenPublicKey string `mapstructure:"ACCESS_TOKEN_PUBLIC_KEY"` PostgreDriver string `mapstructure:"POSTGRES_DRIVER"` In case you were having difficulties in encoding the private and public keys, you can copy and paste the environment variables below into your app.env file to make your life create a config/default.go file and add the following configurations to enable Viper to load the environment variables and make them available in the application. Step 7: Repeat the above process for the refresh token. Step 6: Go back to the Base64 Decode and Encode website and convert it to base64 before adding it to the app.env file as ACCESS_TOKEN_PUBLIC_KEY. Step 5: Navigate back to the website where you generated the keys and copy the corresponding public key. ![]() Step 4: Copy the base64 encoded private key and add it to the app.env file as ACCESS_TOKEN_PRIVATE_KEY. Step 3: Paste the copied private key into the HTML Textarea field on the Base64 Decode and Encode website and click on the “Encode” button to convert it to “ base64“. Later, we’ll decode them back to ASCII strings using the Golang package. Step 2: Copy the generated private key and navigate to this website to convert it to base64. Step 1: Go to this website and click on the “Generate New Keys” button to generate the private and public keys for the JWT tokens. I already added the private and public keys to the app.env file but you can follow the steps below to generate them yourself. Generate the Token Public and Private Keys Retrieve the profile information with the cookies sent by the Gin server.Request a new access token when it expires.Register for a new account with the required credentials.With this Golang, Gin, PostgreSQL JSON Web Token authentication example, the user will be able to do the following: Logout the authenticated user JWT Authentication with Golang and PostgreSQL example Request a new access token when it expires Retrieve the authenticated user’s credentials The Golang Gin server will return some cookies to the client or user’s browser after the credentials have been validated.Ĭlick the Cookies tab in Postman to view the cookies returned by the Gin server after the user was authenticated. Sign in to your account with your credentials You can import the Postman collection used in testing the Golang PostgreSQL JWT authentication and authorization into your own Postman to make your life easier. Golang & PostgreSQL JWT Authentication Overview ![]() Note: Read the Golang & PostgreSQL setup article before implementing the JWT authentication in this article.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |