From the course: Consuming RESTful APIs in Golang
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Token-based authentication - Go Tutorial
From the course: Consuming RESTful APIs in Golang
Token-based authentication
- [Instructor] Let's step things up a bit, shall we? Token-based authentication involves sending unique tokens with each HTTP request for secure API access. Tokens are typically obtained through a separate authentication process, such as OAuth for example, and they offer a more secure alternative to basic authentication and a more ideal for requiring higher security standards. They enable a fine-grained access control over user permissions. Now let's look at how you would implement a token-based authentication as part of your HTTP client. You see on the screen all you need to do is just use the req.Header.Set, and then you set the authorization header key to Authorization, and then you set the value of this header to Bearer, and then the token. Easy peasy. Really easy to do that. Now, what are some tips to keep in mind when working with tokens? Firstly, tokens have a finite lifespan, meaning they expire, they don't live forever. So you'll have to handle token expiration gracefully…