Documentation Index
Fetch the complete documentation index at: https://docs.getmembrane.com/llms.txt
Use this file to discover all available pages before exploring further.
OAuth2 Authentication
This authentication type implements OAuth 2. It can be configured to work with different variations of the standard.Connector Definition
Example OAuth2 connector definition:Authentication Flow
The standard OAuth2 authorization code flow:- Your product initializes authentication by sending user to the
/connectendpoint of Membrane engine. - User is redirected to
authorizeUribuilt usinggetOAuthConfigfunction. - User authenticates at the external app and grants permissions.
- OAuth provider redirects back to redirectUri generated by
getOAuthConfigwith authorization code. - Authorization code is exchanged for access and refresh tokens using
getTokenDatafunction. - (optional) Additional credentials are extracted using
getCredentialsFromAccessTokenResponsefunction. - Token response as well as additional extracted credentials are stored as connection credentials.
- Connection is tested using
testfunction to determine if it was created successfully.
- API requests to the external app are made with a client created by
makeApiClientfunction. - When credentials expire,
refreshCredentialsfunction is called to refresh them.- If you need to extract additional credentials when refreshing them, it is done with
getCredentialsFromRefreshTokenResponsefunction.
- If you need to extract additional credentials when refreshing them, it is done with
getOAuthConfig
Returns OAuth2 configuration used to build the authorization URL and token exchange. Supported implementation types ArgumentsconnectorParameters- Connector configurationconnectionInput- Connection UI parametersredirectUri- The callback URI to usestate- Generated state for the OAuth 2 flow
Example Implementation
Configuration Parameters
| Parameter | Required | Description |
|---|---|---|
clientId | Yes | OAuth2 client ID |
clientSecret | Yes | OAuth2 client secret |
authorizeUri | Yes | Authorization endpoint URL |
tokenUri | Yes | Token exchange endpoint URL |
scopes | No | Array of OAuth scopes to request |
clientAuthLocation | No | Where to send credentials: headers (default), body, or both |
noRefreshToken | No | Set true if API doesn’t return refresh tokens |
skipPkce | No | Set true to disable PKCE (enabled by default) |
extra | No | Additional query parameters for the authorize URI |
Authorize URI Formation
The authorize URI is built by taking yourauthorizeUri and adding these parameters:
client_id- from your configredirect_uri- defaults to{MEMBRANE_API_URI}/oauth-callbackresponse_type=codeaccess_type=offline- to request refresh tokens (setaccess_typetonullinextraparameters to remove it)scope- your scopes joined with spacesstate- as identifier of the current authentication flow- PKCE parameters (unless
skipPkce: true):code_challengecode_challenge_method=S256
- Parameters from
extra
{BASE_URI}/oauth-callback where BASE_URI is your Membrane instance URL.
To override, set oAuthCallbackUri on the integration to use a custom callback URL.
getTokenData
Exchanges the authorization code for access and refresh tokens. Supported implementation types ArgumentsconnectorParameters- Connector configurationconnectionInput- Connection UI parameterscodeVerifier- PKCE code verifierqueryParameters- Query params from OAuth callbackredirectUri- The redirect URI used
tokenUri with:
Body:
grant_type=authorization_codecode- authorization code from callbackredirect_uri- same URI used in authorize step- Client credentials (based on
clientAuthLocation):headers(default): Basic Authorization header with base64-encodedclientId:clientSecretbody:client_idandclient_secretin request body
- PKCE parameters (unless
skipPkce: true):code_verifiercode_challenge_method=S256
Content-Type: application/x-www-form-urlencoded
access_token. If noRefreshToken: false (default), refresh_token is also required.
Example Implementation
getCredentialsFromAccessTokenResponse
Transforms the token response into connection credentials. Supported implementation types ArgumentsconnectorParameters- Connector configurationconnectionInput- Connection UI parametersqueryParameters- Query params from OAuth callbacktokenResponse- Raw response from token exchange
- Extract specific fields from token response
- Make additional API calls to fetch user info
- Transform or normalize credential structure
- Add computed fields (e.g., token expiration timestamp)
getCredentialsFromRefreshTokenResponse
Transforms the refresh token response into updated credentials. Supported implementation types ArgumentsconnectorParameters- Connector configurationconnectionInput- Connection UI parameterscredentials- Current connection credentialstokenResponse- Raw response from refresh token request
- Transform refresh token response structure
- Calculate token expiration from
expires_in - Preserve existing credential fields
makeApiClient
Creates an API client configuration using the connection credentials. Supported implementation types Argumentscredentials- Connection credentials
refreshCredentials
Refreshes expired access tokens using the refresh token. Supported implementation types ArgumentsconnectorParameters- Connector configurationconnectionInput- Connection UI parameterscredentials- Current connection credentials (includingrefresh_token)
tokenUri with:
Body (x-www-form-urlencoded):
grant_type=refresh_tokenrefresh_token- from connection credentialsclient_id- from configclient_secret- from config
Content-Type: application/x-www-form-urlencoded
Common Pitfalls
Missing refresh token configuration
Some APIs don’t return refresh tokens (they use long-lived access tokens instead). Check the API’s token endpoint documentation for the response format. If refresh token is not explicitly included in the response, setnoRefreshToken: true in getOAuthConfig, otherwise connection creation will fail with a missing refresh token error.