Creating a Custom OAuth Application
Creating a Custom OAuth Application
CData embeds OAuth application credentials with CData branding that can be used when connecting to Stripe via a desktop application or a headless machine.However, you must create a custom OAuth application to connect to Stripe via the Web. And since custom OAuth applications seamlessly support all three commonly-used auth flows, you might want to create custom OAuth applications (use your own OAuth Application Credentials) for those auth flows anyway.
Custom OAuth applications are useful if you want to:
- control branding of the authentication dialog;
- control the redirect URI that the application redirects the user to after the user authenticates; or
- customize the permissions that you are requesting from the user.
Before You Begin
Before creating a custom OAuth application, you must install the Stripe CLI and log in. For instructions, see Install the Stripe CLI.
Note: Private apps cannot use OAuth. Your application must be set to public distribution and published to the Stripe App Marketplace before OAuth credentials become active.
Procedure
Creating a custom OAuth application involves:- Creating a custom application, locating your OAuth client credentials, and testing your new application.
- Creating an OAuth installation link.
- Publishing the application to the Stripe App Marketplace.
- Installing and authorizing the application.
Create the Application
- In the Stripe CLI, enter:
stripe apps create <application_name>
- When prompted, enter a display name for your application.
- Confirm or enter a unique App ID.
Note: The App ID becomes the id field in stripe-app.json and serves as the OAuthClientId connection property when establishing a connection. Record this value.
- The CLI will display the location where your application was created.
- The Stripe CLI creates a new directory for your application, initializes a git repository, and generates stripe-app.json, an application manifest file.
- Edit the following fields in stripe-app.json directly, or by using the commands below.
Note: Run the following commands from your application's root directory. Otherwise, the CLI returns a "Manifest files not found" error.
- Set stripe_api_access_type to oauth.
stripe apps set api-access-type oauth
- Set distribution_type to public.
stripe apps set distribution public
- Configure your allowed_redirect_uris directly in stripe-app.json to indicate the URLs to which users are redirected after installing your custom OAuth application (for example, https://example.com/oauth/). The first one in the list is used as the default redirect.
- Set the permissions array to include all the permissions your custom application requires. For a list of valid permissions, see Stripe's Permissions reference.
Your application manifest should now look similar to this:
{ "id": "my-application", // This value is your OAuthClientId "version": "0.0.1", "name": "Your Stripe Application", "icon": "./[YOUR_APPLICATION]_icon_32.png", "permissions": [ // Your application permissions here ], "stripe_api_access_type": "oauth", "distribution_type": "public", "allowed_redirect_uris": [ // Your redirect URIs here ] }
- Set stripe_api_access_type to oauth.
- If desired, add UI extensions to your application to build a custom UI that displays within the Stripe Dashboard. You may also want to add a settings view to enable your users to configure their own settings, or to link to your application's documentation.
- To upload your application to Stripe, enter:
stripe apps upload
Note: After uploading, Stripe must process your files before the application can be installed. The CLI then displays a link to your application's page on the Stripe Dashboard. Navigate to that link and click the Versions tab to view the upload status.
Locate Your Connection Credentials
After creating your application, record the following values. Both values are necessary for Creating the Data Source Name when creating a custom OAuth application.
- OAuthClientId: This is the id value in your stripe-app.json application manifest.
- OAuthClientSecret: Stripe does not issue a separate OAuth client secret. Your Stripe Secret Key serves as the client secret. To retrieve it, go to the Stripe Dashboard, select Developers, click API keys, and copy your Secret key. The secret key is prefixed with sk_live_ (live mode) or sk_test_ (test mode).
Please note that Stripe does not allow access to the entities in the StripeV2 Data Model using secret keys created under test mode. Secret keys created in either live mode or in sandbox mode are allowed.
Furthermore, access to the entities in the StripeV2 Data Model is not allowed through restricted keys.
Test Your Custom Application
To test your new custom application:- Go to your application's details page.
- Open the External test tab.
- Click Get started. This initiates an external test.
- Navigate to the Test OAuth section and access the authorize links. Use these links to test your application against different accounts.
Create the OAuth Install Link
From your web page, redirect to your OAuth install link with the following parameters: https://marketplace.stripe.com/oauth/v2/authorize?client_id=${clientId}&redirect_uri=${redirectUrl}&state=${state}Stripe generates separate links for both live and test modes. You can find the links in the External test tab.
Security Tip: The state parameter is recommended to prevent cross-site request forgery (CSRF) attacks. When users are redirected back to your site, you can confirm that the state parameter has not been modified. For further information, see Prevent CSRF attacks with the state parameter.
Publish the Application
When you are ready to publish your custom OAuth application to the Stripe App Marketplace, submit it for review.When you submit the application for review, you must provide the Marketplace install URL. This URL must link to a page that can initiate the onboarding and installation process with clear instructions (for example, what the app does or what happens when users click "Install") using OAuth install links from the previous step. Additionally, the install URL you provide to the application review must use the public OAuth links from the Settings tab. This link is not the same as the link from the External test tab.
Note: OAuth install links do not work until the application is published, but the Marketplace staff can use the link you provide to install and test your application.
Install and Authorize the Application
- In your browser, open your OAuth install link. If necessary, adjust the query parameters to change the redirect URL to one that your custom application supports.
- View and accept the permissions to install the application.
The application installation process begins. When installation is complete, the user is either redirected to the first callback URL you defined in allowed_redirect_uris in the application manifest, unless you have specified a URL parameter.