Crates.io | bearer |
lib.rs | bearer |
version | 0.2.3 |
source | src |
created_at | 2017-03-22 21:07:57.342256 |
updated_at | 2017-08-02 14:52:22.704919 |
description | Command line utility to generate HTTP Authorization header with bearer tokens. This is achieved with OAuth2 authorization code and refresh token workflow. |
homepage | |
repository | https://github.com/mardiros/bearer |
max_upload_size | |
id | 9099 |
size | 55,088 |
bearer
is a command line utility to generate Authorization HTTP header
with bearer tokens. See RFC 6750.
bearer
comes with a --register
that will ask you the OAuth 2.0
client information to initialize the access and refresh tokens.
Afterwhat, it generate a header that can be used in a curl command:
$ curl -H "$(bearer <client_name>)" "https://<oauth2 api>" | jq
Clients that received refresh token will automatically consume them to retrieve new access token before they expires.
Otherwise the command --refresh
has to be used to get a new access token.
Currently, bearer
is installable using cargo
$ cargo install bearer
Note:
Cargo install binaries in `$HOME/.cargo/bin` directory. Make sure it is in
your `$PATH` environment.
$ bearer my-client-name --register
You have to follow the instruction of the command.
Before continue, register the a client with the following url to the OAuth2 Provider:
http://localhost:6750/callback
Ensure your port is not already open by another service.
If the provider require a https url, please run an https reverse proxy before continue.
Enter the OAuth2.0 Provider Name:
Enter the Client Id:
Enter the Client Secret:
Enter the scope (optional): profile email
Visit to finish the configuration: http://localhost:6750/callback
After input thoses informations your have to open your browser and visit
the http://localhost:6750/callback
url to retrieve tokens. Then
the message below confirm everything is ok.
Tokens retrieved succesfully
$ bearer --list
my-client-name
$ bearer my-client-name
Authorization: Bearer GlwlBMvJI
This is useless if your OAuth2 provider send a refresh token.
Otherwise,
if the access token has been retrieved without refresh token, it cannot be replaced automatically by a new one. Command will failed when the token expires.
$ bearer -c config my-client-without-refresh-token
ERROR: Client must be refreshed. (No Refresh Token)
$ bearer my-client-without-refresh-token --refresh
Visit to finish the configuration: http://localhost:6750/callback
bearer
has been developped under Linux.
It may not work under other operating system. (Not tests)