Using the API
Adding authentication to your project.
How Basic Auth works
Basic uses OAuth 2.0 for authentication.
Here’s a brief overview of how the flow works:
- The user beings the flow by clicking a “Sign in with Basic” button in your app.
- Redirect the user to login page, with the appropriate parameters. (see below for the required parameters)
- The user can login with Basic.id and grants permissions to your app.
- Basic.id redirects the user back to your app with an authorization code.
- Your app can exhange the authorization code for an access token and refresh token.
- Your app can use the access token to make database requests and keep the user logged in.
- If the access token expires, use the refresh token to get a new access token.
In other words:
- Redirect use to
/authorize
- User grants access and redirects back to your app with an authorization code
- Use /token to exchange the code for an access token and refresh token
- Use the access tokens to make database requests
Authentication with the API
Redirect user to /authorize
Redirect the user to the login page, with the appropriate parameters.
Redirect URL:
https://api.basic.tech/authorize
Required Query Parameters
The URL you want the user to be redirected to after they login.
The type of response you want to receive. must be code
.
Your Basic Project ID.
The scopes you want to request. Default is Profile
A random string.
User grants access and is redirected back to your app with an authorization code
The authorization code will be in the URL as a code
query parameter.
For example:
https://your-app.com/callback?code=1234567890
Exchange the authorization code for an access token and refresh token
Make a post request to /token
with the authorization code in the body.
The response will be a JSON object with the access token and refresh token.
Token URL:
https://api.basic.tech/token