#refresh-token #oauth2 #command-line-tool #authorization #http-header #authorization-header #generate

app bearer

命令行工具,用于使用bearer令牌生成HTTP授权头。这是通过OAuth2授权代码和刷新令牌工作流实现的。

5个版本

使用旧的Rust 2015

0.2.3 2017年6月9日
0.2.2 2017年4月8日
0.2.1 2017年4月5日
0.2.0 2017年4月2日
0.1.0 2017年3月22日

#933 in 身份验证

BSD-3-Clause

52KB
1K SLoC

Bearer

Build Status Current Crates.io Version Latests Documentation

基础知识

bearer是一个命令行工具,用于生成带有bearer令牌的Authorization HTTP头。请参阅RFC 6750

bearer包含一个--register,它将询问您OAuth 2.0客户端信息以初始化访问和刷新令牌。

然后,它将生成一个可以在curl命令中使用的头


    $ curl -H "$(bearer <client_name>)" "https://<oauth2 api>" | jq

收到刷新令牌的客户将自动消耗它们,在它们过期之前检索新的访问令牌。

否则,必须使用--refresh命令来获取新的访问令牌。

安装

目前,您可以使用cargo安装bearer


    $ cargo install bearer

注意

Cargo install binaries in `$HOME/.cargo/bin` directory. Make sure it is in
your `$PATH` environment.

注册客户端


    $ bearer my-client-name --register

您必须遵循命令的说明。

    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

输入这些信息后,您必须在浏览器中打开并访问https://127.0.0.1:6750/callback URL以检索令牌。然后,以下消息将确认一切正常。

    Tokens retrieved succesfully

列出已注册客户端


    $ bearer --list
    my-client-name

生成授权头


    $ bearer my-client-name
    Authorization: Bearer GlwlBMvJI

刷新令牌

如果您的OAuth2提供程序发送了刷新令牌,则这毫无意义。

否则,

如果未与刷新令牌一起检索访问令牌,则无法自动替换为新的访问令牌。当令牌过期时,命令将失败。


    $ 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: https://127.0.0.1:6750/callback

支持的平台

bearer是在Linux下开发的。

在其他操作系统下可能无法正常工作。(未测试)

依赖项

~20MB
~491K SLoC