OAT
OAT (short for OAuth Token) is a command line utility wrapper around
advhttp's oauth2Client library. It is designed to make working with
oauth2 simple. It currently supports the following oauth2 Grant
Types:
- Client Credentials
- Password
Getting Started
The first step will be to create your OAT config file. OAT reads this
file to find clients and users based on the command line selectors.
touch ~/.oatconfig
You will need at least a client in the file. The file format follows
the ini file format. A client includes:
- Required
- client_id (string)
- client_secret (string)
- token_endpoint (url)
- Optional
- token_info_endpoint (url)
- scope (A space seperated list of requested scopes)
You can also include a user in the oat config file. When requested
a user will be used in a password grant type. A user includes:
- username (string)
- password (string)
Example File contents:
[myclient]
client_id=clientid
client_secret=clientsecret
token_endpoint=https://www.example.com/oauth2/token
token_info_endpoint=https://www.example.com/oauth2/tokeninfo
scope=https://example.com/auth/scope1 https://example.com/auth/scope2
[myuser]
username=username
password=password
Using OAT
Now that you have your oat file configured, you can use oat. There
is a help document included with oat, to use it type oat -h. OAT
has a number of flags that you can set:
- -c or --client (string) index into ~/.oatconfig file
- -u or --user (string) index into ~/.oatconfig file
- -s or --scope (string seperated list) provide scope
- -U or --username (string) provide username
- -p or --password (string) provide password
- -i or --tokeninfo (bool) return token info object
- -n or --nonewline (bool) don't print newline after token
- -v or --verbose (bool) turn on verbose output
Some Examples:
Our first example will get a new client_credentials token on behalf
of the 'myclient' in the example file:
oat -c myclient
Our next example will get a new password token on behalf of the
'myclient' client and the 'myuser' user in the example file:
oat -c myclient -u myuser
This next example will get a password token on behalf of the 'myclient'
client and then provide user credentials on the command line and also
override the default client scope with new scope on the command line:
oat -c myclient -s 'https://example.com/auth/scope3 https://example.com/auth/scope4' -U user1 -p password
The final example will get a new token and utilize that token in a curl
command:
curl https://api.example.com/cool/story/bro -H "Authorization: Bearer `oat -nc myclient`"
Notice in this example that we used the -n toggle to turn off printing
a newline and we used the backticks to execute the command and then
dump the response back into the input of the curl command.