在我的项目中,我需要一个客户端OAuth2库.该项目是用Erlang编写的.该语言的选项有哪些?
PS我是Erlang的新手,所以文档/示例是必须的.
我们使用Google OAuth2使用HybridAuth 2.4.0对我们的用户进行内部应用程序身份验证,直到大约一周前,我们开始看到来自https://accounts.google.com的越来越多的随机"invalid_request"响应/ o/oauth2/token.
当我说"随机"时,今天更有可能:不工作然后系统地工作大约一分钟(连续多次认证将成功)再次停止工作(即:"invalid_request"响应).
我们尝试升级到最新版本的HybridAuth(2.8.0和现在的2.8.1),它没有解决遇到的问题.
还检查了服务器时间(它是NTP同步和良好),尝试生成一个新的Google API秘密,创建一个新的Google API项目,没有任何更好的运气.
我们认为这是一个环境/服务器问题,因为我们有一个本地DEV环境,其中OAuth2身份验证始终有效.此外,当使用Google API游乐场并使用与PROD服务器相同的有效负载向https://accounts.google.com/o/oauth2/token发出请求时,它会起作用,我们将获得"持有者"access_token.
一些HybridAuth调试日志:
2016-12-06T13:34:56+00:00 -- Endpoint: call adapter [Google] loginFinish()
2016-12-06T13:34:56+00:00 -- Enter OAuth2Client::request( https://accounts.google.com/o/oauth2/token )
2016-12-06T13:34:56+00:00 -- OAuth2Client::request(). dump request params: -- a:5:{s:9:"client_id";s:72:"[obfuscated].apps.googleusercontent.com";s:13:"client_secret";s:24:"[obfuscated]";s:10:"grant_type";s:18:"authorization_code";s:12:"redirect_uri";s:55:"https://[obfuscated]/endpoint?hauth.done=Google";s:4:"code";s:45:"[obfuscated]";}
2016-12-06T13:34:58+00:00 -- OAuth2Client::request(). dump request info: -- a:26:{s:3:"url";s:42:"https://accounts.google.com/o/oauth2/token";s:12:"content_type";s:31:"application/json; charset=utf-8";s:9:"http_code";i:400;s:11:"header_size";i:428;s:12:"request_size";i:318;s:8:"filetime";i:-1;s:17:"ssl_verify_result";i:0;s:14:"redirect_count";i:0;s:10:"total_time";d:2.5824850000000001;s:15:"namelookup_time";d:2.0000000000000002E-5;s:12:"connect_time";d:0.14088800000000001;s:16:"pretransfer_time";d:0.426647;s:11:"size_upload";d:753;s:13:"size_download";d:33;s:14:"speed_download";d:12;s:12:"speed_upload";d:291;s:23:"download_content_length";d:-1;s:21:"upload_content_length";d:753;s:18:"starttransfer_time";d:2.427991;s:13:"redirect_time";d:0;s:12:"redirect_url";s:0:"";s:10:"primary_ip";s:14:"[obfuscated]";s:8:"certinfo";a:0:{}s:12:"primary_port";i:443;s:8:"local_ip";s:11:"[obfuscated]";s:10:"local_port";i:35617;}
2016-12-06T13:34:58+00:00 -- OAuth2Client::request(). dump request result: -- s:33:"{
"error" : "invalid_request"
}";
Run Code Online (Sandbox Code Playgroud)
任何关于进一步调查的方向的线索都将非常感激:)
几年前,我创建了一个小型Python程序,该程序能够使用oauth2client维护日历,现在已弃用并替换为google.auth-但我找不到任何有用的文档,并且我的程序停止工作,抱怨_module KeyError没人出现解决了,除了升级。
我不知道如何用google.auth替换oauth2client:
import datetime
import httplib2
import os
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools
Run Code Online (Sandbox Code Playgroud)
...
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('calendar', 'v3', http=http)
Run Code Online (Sandbox Code Playgroud) python google-api oauth2client google-oauth google-api-python-client
我查找并搜索了其他人,肯定是其他人正在使用API,在身份验证时,我似乎找不到正确的范围参数值:
我已经查看了所有这些作用域列表,没什么,尝试过OAuth 2.0游乐场,没有翻译。
任何线索都欢迎,谢谢。
错误信息:
Error: invalid_request
Missing required parameter: scope
Learn more
Request Details
Run Code Online (Sandbox Code Playgroud)
更新资料
用户Ezra解释说,翻译API不需要OAuth2身份验证。
我沿着这条路走这条路:
我正在尝试使示例代码在这里工作:
而且没有apiclient.discovery模块
from apiclient.discovery import build
Run Code Online (Sandbox Code Playgroud)
我去了寻找那它落在我这里这个快速启动配置 这给了我一个自动生成翻译API项目在这里:
这个应该为Translation API量身定制的入门项目包括一整套OAuth配置,因此由于这里提到的错误,我最终提出了一个问题
exception calling translation api: <HttpError 400 when requesting https://www.googleapis.com/language/translate/v2?q=zebra&source=en&alt=json&target=fr&key=MYSECRETKEYWENTHERE returned "Bad Request">
Run Code Online (Sandbox Code Playgroud)
我用来进行上述调用的代码,这种方式的错误是:
service = build('translate', 'v2',
developerKey='MYSECRETKEYWENTHERE')
result = service.translations().list(
source='en',
target=lang,
q='zebra'
).execute()
Run Code Online (Sandbox Code Playgroud)
如果我直接拨打该错误抱怨的电话,那就可以了
https://www.googleapis.com/language/translate/v2?key=MYSECRETKEYWENTHERE&q=zebra&target=fr&alt=json&source=en
Run Code Online (Sandbox Code Playgroud)
再次更新
好的,我从示例项目中删除了所有OAuth代码,然后再次运行它,最后发现我的密钥中有错字...
感谢您的回答!
。
谢谢
google-app-engine oauth-2.0 google-api-client oauth2client oauth2-playground
我正在尝试验证我的凭据以访问GMail API.以前我使用run()OAuth2中的方法和代码执行credentials = tools.run(flow, STORAGE, http=http)此操作,但现在这是一个不推荐使用的方法.我现在正在使用该run_flow()方法来验证我的凭据.
import httplib2
import argparse
from apiclient import errors
from apiclient.discovery import build
from oauth2client import tools
from oauth2client.file import Storage
from oauth2client.client import flow_from_clientsecrets
CLIENT_SECRET_FILE = 'your_client_secret.json'
OAUTH_SCOPE = 'https://www.googleapis.com/auth/gmail.modify'
STORAGE = Storage('gmail.storage')
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE, scope=OAUTH_SCOPE)
http = httplib2.Http()
credentials = STORAGE.get()there are credentials, no reauth is needed
#parser = argparse.ArgumentParser(parents=[tools.argparser])
#flags = parser.parse_args() #Put your arguments in the parenthesis
if credentials is None or credentials.access_token_expired:
credentials …Run Code Online (Sandbox Code Playgroud) oauth-2.0 oauth2client google-oauth google-api-python-client gmail-api
我正在尝试在GAE Python中实现Google Identity Toolkit(gitkitv3).用户登录网站后,我收到以下错误:
'PKCS12 format is not supported by the PyCrpto library. '
NotImplementedError: PKCS12 format is not supported by the PyCrpto library. Try converting to a "PEM" (openssl pkcs12 -in xxxxx.p12 -nodes -nocerts > privatekey.pem) or using PyOpenSSL if native code is an option.
Run Code Online (Sandbox Code Playgroud)
基于SO回复,我在x.p12文件上运行以下命令,并使用生成的privatekey.pem文件:
openssl pkcs12 -passin pass:notasecret -in x.p12 -nocerts -passout pass:notasecret -out key.pem
openssl pkcs8 -nocrypt -in key.pem -passin pass:notasecret -topk8 -out privatekey.pem
Run Code Online (Sandbox Code Playgroud)
现在,我收到以下错误:
'X509 certs are not supported by the PyCrypto library. …Run Code Online (Sandbox Code Playgroud) google-app-engine pycrypto oauth-2.0 oauth2client google-oauth
我无法让gmail api工作.我正在使用JWT进行服务器到服务器身份验证.
google-api-python-client==1.4.0
httplib2==0.9
oauth2client==1.4.7
pycrypto==2.6.1
Run Code Online (Sandbox Code Playgroud)
我的代码看起来像这样.
with open(CLIENT_SECRET_FILE) as f:
data = json.loads(f.read())
private_key = data['private_key']
client_email = data['client_email']
credentials = SignedJwtAssertionCredentials(client_email, private_key, scope=OAUTH_SCOPE)
http = credentials.authorize(http)
gmail_service = build('gmail', 'v1', http=http)
try:
threads = gmail_service.users().messages().list(userId='me').execute()
except Exception as e:
print e
print e.content
Run Code Online (Sandbox Code Playgroud)
回应是
<HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages?alt=json returned "Bad Request">
{
"error": {
"errors": [
{
"domain": "global",
"reason": "failedPrecondition",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我从google API获取oauth 2.0令牌时遇到问题.我目前正在为Android编写应用程序,我希望有三种登录方式 - 通过facebook(完成),通过自定义oauth 2.0提供程序(也已完成)和通过谷歌加 - 它给我带来了很多问题.我需要在设备上获取访问令牌,并将其进一步传递给后端应用程序.
我尝试使用GoogleApiClient(不推荐使用PlusClient - 通过 http://developer.android.com/reference/com/google/android/gms/plus/PlusClient.html),但看不到像getAccessToken这样的方法.
目前我尝试使用socialauth库,但由于缺少文档(这里是一些代码)我陷入困境
private SocialAuthAdapter mSocialAdapter;
... in onCreate()
mSocialAdapter = new SocialAuthAdapter(new GooglePlusSocialAuthListener());
try {
mSocialAdapter.addConfig(Provider.GOOGLEPLUS, key_from_google_developers_console, secret,
"https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email");
mSocialAdapter.addCallBack(Provider.GOOGLEPLUS,
"http://localhost:3000/api/auth/gplus/callback");
}
catch (Exception e) {
e.printStackTrace();
}
mSocialAdapter.authorize(LoginActivity.this, Provider.GOOGLEPLUS);
Log.e("TOKEN HERE ", mSocialAdapter.getCurrentProvider().getAccessGrant().getKey());
Run Code Online (Sandbox Code Playgroud)
有人可以帮我拿到这个令牌吗?无论是通过socialauth还是通过GoogleApiClient都没关系.
我已经在我的Django项目中为Google OAuth2 实现了python-social-auth库,并能够成功使用它登录用户。该库将access_token收到的信息存储在Google OAuth2流的响应中。
我的问题是:使用google-api-python-client似乎依赖于创建和授权credentials对象,然后使用它来构建API,service如下所示:
...
# send user to Google consent URL, get auth_code in response
credentials = flow.step2_exchange(auth_code)
http_auth = credentials.authorize(httplib2.Http())
from apiclient.discovery import build
service = build('gmail', 'v1', http=http_auth)
# use service for API calls...
Run Code Online (Sandbox Code Playgroud)
由于我是从access_tokenpython-social-auth提供的开始,因此如何service为未来的API调用创建和授权API客户端?
编辑:澄清一下,上面的代码来自Google提供的示例。
python oauth2client google-api-python-client python-social-auth google-oauth2
我在Golang应用程序中工作,这个连接到Oauth2服务,现在我有刷新令牌,我需要用它获得一个新的访问令牌,我正在使用golang.org/x/oauth2但它不会成功,所以有一些东西,我失踪了,目前我有:
refresh_token := "some_refresh_token"
var conf = oauth2.Config{
ClientID:MY_CLIENT,
ClientSecret:MY_CLIENT_SECRET,
Scopes:[]string{"refresh_token"},
RedirectURL:"https://mydomain/callback",
Endpoint: oauth2.Endpoint{
AuthURL:"myoauth2Cluster.com/oauth2/auth",
TokenURL: "myoauth2Cluster.com/oauth2/token",
},
}
t := new (oauth2.Token)
t.RefreshToken=refresh_token
myclient := conf.Client(context.Background(),t)
req, err := http.NewRequest("GET",DontKnowWhichURLhere , nil)
if err != nil {
fmt.Println("error:",err.Error())
}
mrr, er := myclient.Do(req)
if(er!=nil){
fmt.Println(er.Error())
}else{
fmt.Println("status code:",mrr.StatusCode)
}
Run Code Online (Sandbox Code Playgroud)
但我得到404状态,我检查了Oauth2服务器的日志,我有
msg="completed handling request" measure#https://myOauth2Cluster.latency=100648 method=GET remote=xxx.xxx.xx.xxx request="/" status=404 text_status="Not Found" took=100.648µs
Run Code Online (Sandbox Code Playgroud)
另外,我不确定在创建http.NewRequest它应该是回调的时候我应该坚持哪个URL ?或Oauth2服务器的网址?
如果有一些如何使用这个库更新访问令牌的例子会很好,但目前我还没有找到它
我已经在OAuth2中为该请求成功实现了对新令牌的请求:
curl --request POST --url https://some-autentication-server.com/token --header 'content-type: content-type'
Run Code Online (Sandbox Code Playgroud)
提供的身体为:
{
"grant_type"="password",
"username"="username",
"password"="password"
"client_id"="my-client-id"
}
Run Code Online (Sandbox Code Playgroud)
认证后,资源服务器curl可以通过以下方式访问:
curl -i -H "authorization: Bearer token-received-from-auth-server" \
-H "accept: application/json" \
-H "request-id: abcdef" \
-H "consent-status: optedIn" \
-X GET https://my-resource-server.com/path
Run Code Online (Sandbox Code Playgroud)
我在Spring Boot中使用的配置是这样的:
@EnableOAuth2Client
@Configuration
public class OauthClientConfig {
@Bean
public CloseableHttpClient httpClient() throws Exception {
CloseableHttpClient httpClient = null;
try {
httpClient = HttpClientBuilder.create()
.setProxy(new HttpHost("PROXY_HOST_NAME", 3000, "http"))
.build();
} catch (Exception e) {
throw e;
}
return httpClient;
}
@Bean …Run Code Online (Sandbox Code Playgroud) java oauth-2.0 oauth2client spring-boot spring-security-oauth2
我正在尝试使用 spring-boot 设置 oauth2 客户端。我对我的有这个依赖pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我的这个配置application.properties:
spring.security.oauth2.client.registration.mercadolivre.client-id=...
spring.security.oauth2.client.registration.mercadolivre.client-secret=...
Run Code Online (Sandbox Code Playgroud)
和这个安全配置类:
@Configuration
public class Security extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login();
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行应用程序时,给我这个错误:
Caused by: java.lang.IllegalStateException: Provider ID must be specified for client registration 'mercadolivre'
at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getBuilder(OAuth2ClientPropertiesRegistrationAdapter.java:95) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistration(OAuth2ClientPropertiesRegistrationAdapter.java:61) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.lambda$getClientRegistrations$0(OAuth2ClientPropertiesRegistrationAdapter.java:53) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar!/:2.2.6.RELEASE]
at java.base/java.util.HashMap.forEach(HashMap.java:1338) ~[na:na]
at org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(OAuth2ClientPropertiesRegistrationAdapter.java:52) …Run Code Online (Sandbox Code Playgroud) oauth2client ×12
oauth-2.0 ×6
google-oauth ×3
python ×3
gmail-api ×2
google-api ×2
spring-boot ×2
android ×1
api ×1
erlang ×1
go ×1
google-plus ×1
hybridauth ×1
java ×1
oauth ×1
pycrypto ×1