命令行google oauth工具
google-oauth2l的Python项目详细描述
OAuth2l
----
[![构建状态](https://travis-ci.org/google/oauth2l.svg?branch=master)(https://travis ci.org/google/oauth2l)
[![覆盖范围](https://coveralls.io/repos/google/oauth2l/badge.svg?branch=master)(https://coveralls.io/r/google/oauth2l?分支=主)
[![pypi](https://img.shields.io/pypi/v/google-oauth2l.svg)](https://pypi.python.org/pypi/google-oauth2l)
[![版本](https://img.shields.io/pypi/pyversions/google-oauth2l.svg)(https://pypi.python.org/pypi/google-oauth2l)
`oauth2l`(发音为"oauth tool")是一个简单的命令行工具,用于
(https://developers.google.com/identity/protocols/oauth2)。
它的主要用途是获取和打印oauth2.0访问令牌,它可以与其他命令行工具和shell脚本一起使用。
此工具还演示了如何设计一个简单易用的oauth
2.0客户端体验。如果您需要用
另一种编程语言重新实现此功能,请使用[go oauth2l](go/oauth2client)
作为参考代码。
环境:
*在google计算引擎(gce)和google容器(gke)中运行时,如果当前服务帐户可用,则使用其凭据。
*在具有活动google cloud sdk的用户上下文中运行时
(gcloud)会话,它使用当前的gcloud凭据。
*当使用命令选项"--json xxx"运行时,其中"xxx"指向从
[谷歌云控制台](https://console.cloud.google.com/api/credentials)下载的json凭据文件,
`oauth2l`使用该文件启动oauth会话。文件可以是
服务帐户密钥或OAuth客户端ID。
*当使用命令选项"-sso{email}"运行时,它调用
外部"sso"命令来检索单点登录(sso)访问令牌。
注意:`oauth2l'将OAuth凭据缓存在用户家中避免重复提示用户。
先安装"pip"。
$sudo easy廑u在操作系统下安装pip
请尝试在当前用户下
$pip install google-oauth2l--upgrade--ignore installed
典型的"~/.local/bin"(在Linux上)和"~/library/python/2.7/bin"(在Mac上)。
$pip install——用户google-oauth2l
````
流动。您可以使用外部单点登录(sso)命令从
[谷歌云控制台](https://console.cloud.google.com/api/credentials)下载该文件。
``````
$oauth2l fetch--json~/service_account.json cloud platform
`
令牌。
该命令将OAuth访问令牌输出到其stdout。默认
命令用于google的公司sso。例如:
```
$sso me@example.com scope1 scope2
````
###--jwt
当设置此选项并且在"--json"选项中指定的json文件
是服务帐户密钥文件时,将生成由服务帐户
私钥签名的jwt令牌。设置此选项时,不需要作用域列表,但必须提供一个jwt访问群体。
示例:
````
oauth2l fetch--jwt--json~/service_ account.json https://pubsub.googleapis.com/google.pubsub.v1.publisher
````
\commands
\fetch
fetch并打印指定OAuth作用域的访问令牌。例如,
以下命令打印以下OAuth2作用域的访问令牌:
*https://www.googleapis.com/auth/userinfo.email
*https://www.googleapis.com/auth/cloud platform
````
$OAuth2l fetch userinfo.email云平台
ya29.zyxwwwwvutsrqnmolkjjhgfedcba
$oauth2l fetch-f json userinfo.email云平台
{{
"访问令牌":"ya29.zyxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqmqjjhgfedcba",
"令牌有效期":"2017-02-27t21:20:20:47z",
"用户代理":"oauth2l/1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0
注意:"-f"标志指定输出格式。支持的格式有:
bare(默认)、header、json、json_u compact、pretty。
除了输出是http头格式之外:
```
$oauth2l header userinfo.email
authorization:bearer ya29.zyxwvutsrqpnmolkjihgfedcba
```
header命令设计为易于与"curl"一起使用。例如,
以下命令使用pubsub api列出所有pubsub主题。
````
$curl-h"$(oauth2l header pubsub)"https://pubsub.google apis.com/v1/projects/my project id/topics
```
您可以为它定义一个
shell别名。例如:
```
$alias gcurl=-curl-h"$(oauth2l header cloud platform)"-h"内容类型:application/json"'
$gcurl'https://pubsub.googleapis.com/v1/projects/my project id/topics'
```
info
打印有关有效令牌的信息。这始终包括作用域
和过期时间的列表。如果令牌具有
`https://www.googleapis.com/auth/userinfo.email`或
`https://www.googleapis.com/auth/plus.me`作用域,则它还会打印已验证身份的电子邮件地址。
````
$oauth2l info$(oauth2l fetch pubsub)
{
"过期时间":3599,
"scope":"https://www.googleapis.com/auth/pubsub",
"email":"user@gmail.com"
…
}
`````
\test
这将有效令牌的退出代码设置为0,否则设置为1,
,这在shell管道中很有用。
`````
$oauth2l test ya29.zyxwvutsrqpnomolkjihgfedcba
$echo$?
0
$oauth2l测试ya29.justkiddingmadethisoneup
$echo$?
1
````
我们在
文件`~/.oauth2l.token`.
`````
$oauth2l reset
```
----
[![构建状态](https://travis-ci.org/google/oauth2l.svg?branch=master)(https://travis ci.org/google/oauth2l)
[![覆盖范围](https://coveralls.io/repos/google/oauth2l/badge.svg?branch=master)(https://coveralls.io/r/google/oauth2l?分支=主)
[![pypi](https://img.shields.io/pypi/v/google-oauth2l.svg)](https://pypi.python.org/pypi/google-oauth2l)
[![版本](https://img.shields.io/pypi/pyversions/google-oauth2l.svg)(https://pypi.python.org/pypi/google-oauth2l)
`oauth2l`(发音为"oauth tool")是一个简单的命令行工具,用于
(https://developers.google.com/identity/protocols/oauth2)。
它的主要用途是获取和打印oauth2.0访问令牌,它可以与其他命令行工具和shell脚本一起使用。
此工具还演示了如何设计一个简单易用的oauth
2.0客户端体验。如果您需要用
另一种编程语言重新实现此功能,请使用[go oauth2l](go/oauth2client)
作为参考代码。
环境:
*在google计算引擎(gce)和google容器(gke)中运行时,如果当前服务帐户可用,则使用其凭据。
*在具有活动google cloud sdk的用户上下文中运行时
(gcloud)会话,它使用当前的gcloud凭据。
*当使用命令选项"--json xxx"运行时,其中"xxx"指向从
[谷歌云控制台](https://console.cloud.google.com/api/credentials)下载的json凭据文件,
`oauth2l`使用该文件启动oauth会话。文件可以是
服务帐户密钥或OAuth客户端ID。
*当使用命令选项"-sso{email}"运行时,它调用
外部"sso"命令来检索单点登录(sso)访问令牌。
注意:`oauth2l'将OAuth凭据缓存在用户家中避免重复提示用户。
先安装"pip"。
$sudo easy廑u在操作系统下安装pip
请尝试在当前用户下
$pip install google-oauth2l--upgrade--ignore installed
典型的"~/.local/bin"(在Linux上)和"~/library/python/2.7/bin"(在Mac上)。
$pip install——用户google-oauth2l
````
流动。您可以使用外部单点登录(sso)命令从
[谷歌云控制台](https://console.cloud.google.com/api/credentials)下载该文件。
``````
$oauth2l fetch--json~/service_account.json cloud platform
`
令牌。
该命令将OAuth访问令牌输出到其stdout。默认
命令用于google的公司sso。例如:
```
$sso me@example.com scope1 scope2
````
###--jwt
当设置此选项并且在"--json"选项中指定的json文件
是服务帐户密钥文件时,将生成由服务帐户
私钥签名的jwt令牌。设置此选项时,不需要作用域列表,但必须提供一个jwt访问群体。
示例:
````
oauth2l fetch--jwt--json~/service_ account.json https://pubsub.googleapis.com/google.pubsub.v1.publisher
````
\commands
\fetch
fetch并打印指定OAuth作用域的访问令牌。例如,
以下命令打印以下OAuth2作用域的访问令牌:
*https://www.googleapis.com/auth/userinfo.email
*https://www.googleapis.com/auth/cloud platform
````
$OAuth2l fetch userinfo.email云平台
ya29.zyxwwwwvutsrqnmolkjjhgfedcba
$oauth2l fetch-f json userinfo.email云平台
{{
"访问令牌":"ya29.zyxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwqmqjjhgfedcba",
"令牌有效期":"2017-02-27t21:20:20:47z",
"用户代理":"oauth2l/1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0
注意:"-f"标志指定输出格式。支持的格式有:
bare(默认)、header、json、json_u compact、pretty。
除了输出是http头格式之外:
```
$oauth2l header userinfo.email
authorization:bearer ya29.zyxwvutsrqpnmolkjihgfedcba
```
header命令设计为易于与"curl"一起使用。例如,
以下命令使用pubsub api列出所有pubsub主题。
````
$curl-h"$(oauth2l header pubsub)"https://pubsub.google apis.com/v1/projects/my project id/topics
```
您可以为它定义一个
shell别名。例如:
```
$alias gcurl=-curl-h"$(oauth2l header cloud platform)"-h"内容类型:application/json"'
$gcurl'https://pubsub.googleapis.com/v1/projects/my project id/topics'
```
info
打印有关有效令牌的信息。这始终包括作用域
和过期时间的列表。如果令牌具有
`https://www.googleapis.com/auth/userinfo.email`或
`https://www.googleapis.com/auth/plus.me`作用域,则它还会打印已验证身份的电子邮件地址。
````
$oauth2l info$(oauth2l fetch pubsub)
{
"过期时间":3599,
"scope":"https://www.googleapis.com/auth/pubsub",
"email":"user@gmail.com"
…
}
`````
\test
这将有效令牌的退出代码设置为0,否则设置为1,
,这在shell管道中很有用。
`````
$oauth2l test ya29.zyxwvutsrqpnomolkjihgfedcba
$echo$?
0
$oauth2l测试ya29.justkiddingmadethisoneup
$echo$?
1
````
我们在
文件`~/.oauth2l.token`.
`````
$oauth2l reset
```