If you are implementing server-to-server authentication with Daisycon, this guide will help you set up oAuth using a CLI (Command-Line Interface) flow. Follow the steps below to get started.
Getting Started
Before setting up oAuth via CLI, ensure you have:
- A developer account and app created within your account
Important: When creating your app, request only the permissions your app needs. For example, if the app only fetches statistics, avoid requesting permissions to modify user or account information. The user connecting the app must also have these permissions.
During app creation, we recommend registering the Daisycon CLI Authorized Redirect URL as the Authorized redirect URI for your app.
CLI Authorized Redirect URL
https://login.daisycon.com/oauth/cli
Once configured, your app setup might look like this:
oAuth Flow: Out-of-the-Box Solutions
Daisycon provides two ready-to-use solutions for oAuth over CLI:
Refer to the README.md
file in each repository for instructions. Below, we explain how to use the PHP example.
Using the PHP Example
Run the PHP script with your desired arguments. Use --help
to view all options. We recommend providing the following arguments:
- clientId: Your application’s Client ID
- clientSecret: Your application’s Client Secret
- outputFile: The file where tokens will be stored
Example command:
php PHP/cli-client.php --clientId="YOUR_CLIENT_ID" --clientSecret="YOUR_CLIENT_SECRET" --outputFile="daisycon-api-tokens.json"
After running the command, the script will prompt you to open a URL in your browser, complete the CLI login process, and paste the response code back into the terminal. It will look like this:
Once you paste the code, the script will exchange it for an access token and a refresh token. If you specified an output file, the tokens will be saved there; otherwise, they will be displayed on the screen.
These tokens can be used for automating API calls. As long as you refresh the tokens within 30 days and do not revoke them, no further user interaction is required.
oAuth Flow: Manual Implementation
If you cannot use the PHP or TypeScript/Node/JavaScript examples, you can implement your own CLI oAuth flow. Refer to the code in our examples for guidance. Follow the standard OAuth flow with these adjustments:
- Instead of redirecting the user to our login domain, output the URL and instruct the user to open it manually in their browser.
- Use the CLI Authorized Redirect URL to display the authorization code on screen.
- Prompt the user to paste the authorization code back into your CLI tool to exchange it for an access token.
Conclusion
Using Daisycon’s oAuth over CLI allows for secure and flexible server-to-server communication. Whether using our ready-to-go solutions or building your own, this approach ensures smooth API integration.