Authentication
Introduction
SubsBase uses JWT as the main means to authenticate any operation (Query or Mutation). The token follows the standard JWT format and it is to be sent with any request in a Authorization
header and preceded by the keywords Bearer
.
Example
POST https://api.subsbase.io/core/graphql
Authorization: Bearer {your received jwt goes here}
Type of Tokens
There are 2 types of tokens that would be used to interact with the SubsBase Backend.
- Server Tokens
- Customer Tokens (your subscriber/customer)
Server Tokens
Server Tokens are to be used for backend-to-backend communication only. It assumes that it is coming from a trusted source and would be consumed by your backends.
A server token is requested through the following Query to https://api.subsbase.io/auth
. The server token could then be used to either Query or Mutate data directly or used to authenticate a customer for further processing.
query GetApiToken {
getApiToken(siteId: "{your site id}", apiSecret: "{your api secret}") {
isSuccess
value
message
}
}
- A
true
value in theisSuccess
fields indicates a successful operation and the token would in thevalue
field. Otherwise, themessage
would include more information about any error(s) that might have occurred - You can find your API secret in the Settings > Webhook and API Settings page on your Admin Portal.
{your site id}
is the case-sensitive site id you want to use and which contains the plans you need to attach. Your SubsBase Admin Portal link is in the form ofhttps://{your_siteId}.subsbase.io
Customer Tokens
Customer tokens are used to authenticate a specific customer. This is usually used when you want to allow a customer to manage their own subscription allowing them to access, edit, pause, or cancel their plans. The token is expected to be returned back to the browser with additional requests originating from the browser within a user's active session.
A server token is requested through the following Query to https://api.subsbase.io/auth/graphql
.
Authorization
header
query GetCustomerToken {
getCustomerToken(
customerId: "{the customerId whom will proceed with the token}"
) {
isSuccess
value
message
}
}
- A
true
value in theisSuccess
fields indicates a successful operation and the token would in thevalue
field. Otherwise, themessage
would include more information about any error(s) that might have occurred
Data flow
