Bubble API - Authentication
Authenticating users when using the Bubble API
Overview
Overview
This article will cover several methods to authenticate a user when trying to access a Bubble Workflow API or Bubble's Data API endpoint.
Goals of the article
The goal of the article is to provide a clear example of the authentication methods you can use.
Authentication methods
There are several methods to authenticate the user. The app or client context will help us decide which one to use in each case.
Methods (read Bubble's manual with extended info):
Use an API Token generated in the API section in the Settings Tab:
When you authenticate with such an API Token, the call is run in the context of an admin user of the app, who has access to all data. This method is not the best if we need to limit what the user can do or not do. At least it should be used with caution.
Create Sign up/Login API workflows:
This is useful for developing an alternative front-end to the Bubble app, such as a native app.
We can sign up and log users in. This user, once the workflow is being executed, will be the 'Current user,' who you can access with actions.
Privacy rules will apply to this user as they would if the user was logging in the Bubble app and using it in their own browser.
The user receives a token that expires in 86400 seconds. You can login the user again to obtain a new token.
Session cookie
No authentication:
In some cases, you may want to enable calls that aren't authenticated, e.g., to let a user sign up or login to the app.
To enable this, check the box 'This workflow can be run without authentication' at the workflow level.
When a workflow is run under such circumstances, the privacy rules that apply are the one for 'everyone.'
Create Sign up/Login API workflows
Create a signup workflow:
Create a login workflow:
API call to the sign up workflow example:
Both the signup and the login workflow responses use the same schema:
Then you can have any kind of workflow. The user will be the one identified on the signup or login API call from where you got the token.
In this example we'll return the App settings object unique id and the number of users the app has:
The API call. In this case we won't be passing any parameters, just the token as a Bearer token:
The response from our app API:
Demo app
More information
Last updated