Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i use oauth 2.0 for any application #134

Open
nayanmathur25 opened this issue Jul 23, 2024 · 2 comments
Open

how can i use oauth 2.0 for any application #134

nayanmathur25 opened this issue Jul 23, 2024 · 2 comments

Comments

@nayanmathur25
Copy link

I would like to know how can i use oauth 2.0 for my application . I have the necessary details like client_id and password and url.
It will be really useful if you can answer what all details i have to mentioned in --headers file and the format.

@en-milie
Copy link
Contributor

en-milie commented Jul 25, 2024

You can use the --authRefreshScript argument. You need to create a script that does a curl with the username and password, client_id, etc., parse the result and get the token and echo it. Something like (name it ./refresh.sh):

#!/bin/bash

curl -s --location --request POST 'https://api.server/token' \
--header 'Authorization: Basic XXX' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=user' \
--data-urlencode 'password=pwd' | jq -r '"Bearer "+.access_token'

And then:

cats -s SERVER -c CONTRACT -H "Authorization-Header-Name=auth_script" --authRefreshScript="./refresh.sh"

Exactly the same as above, but you add a new argument to refresh the token periodically:

cats -s SERVER -c CONTRACT -H "Authorization-Header-Name=auth_script" --authRefreshScript="./refresh.sh" --authRefreshInterval=500

This will cal the ./refresh.sh script every 5 minutes to get a refresh token.

Please make sure you replace the Authorization-Header-Name with the exact name expected by the service.

Does this help?

@en-milie
Copy link
Contributor

@nayanmathur25 Does it work with the suggested approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants