标签: oauth2client

您指定的签名指纹已被其他Android OAuth2客户端使用

前段时间我Oauth2 client id在Google API控制台中为Android应用程序创建了一个示例项目(让我们称之为"示例项目").我还添加了SHA1 fingerprint包名(例如com.package.name).

我的错误是已经存在具有相同包名的应用程序.现在我需要Oauth2 client id在包含名称的"有效项目"中创建一个for android应用程序,我之前添加com.package.nameSHA1 fingerprint它.显然,当我尝试添加此指纹时,我收到了一个错误.

The signing fingerprint you specified is already used by another Android OAuth2 client.
Run Code Online (Sandbox Code Playgroud)

之后我记得"示例项目"并client id从该项目中删除.问题是我仍然无法为包名添加此指纹com.package.name.Client id被删除,但我仍然有与上面相同的错误.

那么我是否有可能在另一个项目中将此指纹用于相同的包名称?

android google-api google-plus oauth2client google-oauth

24
推荐指数
4
解决办法
2万
查看次数

如何在没有gflags的情况下获取Google Analytics凭据 - 使用run_flow()代替?

这可能需要一秒钟来解释所以请耐心等待:

我正在开展一个工作项目,要求我提供谷歌分析数据.我最初是在这个链接之后做的,所以在安装了API客户端pip install --upgrade google-api-python-client并设置了类似的东西后client_secrets.json,它需要安装gflags才能执行run()语句.(即credentials = run(FLOW, storage))

现在,我收到错误消息安装gflags或更好地使用run_flow()(确切的错误消息是这样):

NotImplementedError:必须安装gflags库才能使用tools.run().请安装gflags或最好切换到使用tools.run_flow().

我最初使用gflags(几个月前),但它与我们的框架(金字塔)不兼容,所以我们将其删除,直到我们弄清楚问题是什么.之所以最好从gflags切换到run_flow()因为gflags已被弃用,所以我不想像我一样使用它.我现在要做的就是切换到使用run_flow()

这个问题是run_flow()需要将命令行参数发送给它,而这不是命令行应用程序.我找到了一些有用的文档,但我仍然坚持为run_flow()函数构建标志.

在展示代码之前还有一件事需要解释.

run_flow()有三个参数(文档在这里).它就像流程和存储一样run(),但它也需要一个标志对象.gflags库构建了一个ArgumentParseroauth2client执行方法中使用的标志对象.

一些有助于构建argumentParser对象的其他链接:

第二个链接非常有助于了解它是如何执行的,所以现在当我尝试做类似的事情时,sys.argv拉入我运行aka的虚拟环境的位置pserve并拉入我的.ini文件(它将我的机器的凭据存储到运行虚拟环境).但这引发了一个错误,因为它期待别的东西,这就是我被困住的地方.

  • 我不知道我需要构建什么标志对象来发送 run_flow()
  • 我不知道我需要传递什么argv参数才能使语句flags = parser.parse_args(argv[1:])检索正确的信息(我不知道应该是什么样的正确信息)

码:

CLIENT_SECRETS = client_file.uri
MISSING_CLIENT_SECRETS_MESSAGE = '%s is missing' % CLIENT_SECRETS …
Run Code Online (Sandbox Code Playgroud)

python google-analytics google-analytics-api oauth2client google-api-python-client

24
推荐指数
1
解决办法
4225
查看次数

在oauth2 SignedJwtAssertionCredentials中得到'invalid_grant'

我试图在服务器到服务器JSON API方案中创建oauth2 access_token.但它失败了invalid_grant错误,请帮忙.

from oauth2client.client import SignedJwtAssertionCredentials

KEY_FILE = 'xxxxxxxxxxxx-privatekey.p12'

with open(KEY_FILE, 'r') as fd:
    key = fd.read()

SERVICE_ACCOUNT_EMAIL = 'xxxxxx.apps.googleusercontent.com'

credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
      scope="https://www.googleapis.com/auth/datastore https://www.googleapis.com/auth/userinfo.email",
      token_uri='https://accounts.google.com/o/oauth2/token')


assertion = credentials._generate_assertion()

h = httplib2.Http()
credentials._do_refresh_request(h.request)
Run Code Online (Sandbox Code Playgroud)

我得到了

Traceback (most recent call last):
  File "/Users/pahud/Projects/oauth2client/x.py", line 24, in <module>
    credentials._do_refresh_request(h.request)
  File "/Users/pahud/Projects/oauth2client/oauth2client/client.py", line 710, in _do_refresh_request
    raise AccessTokenRefreshError(error_msg)
oauth2client.client.AccessTokenRefreshError: invalid_grant
[Finished in 0.7s with exit code 1]
Run Code Online (Sandbox Code Playgroud)

http://i.stack.imgur.com/iGGYx.png

oauth2client google-cloud-datastore

14
推荐指数
1
解决办法
6875
查看次数

如何在MVC 5 Web应用程序和Web API 2应用程序之间共享访问令牌

在这个例子中,我让用户登录到(MVC 5)Web应用程序,该应用程序然后充当代理以登录(Web API 2)API(使用基本的SSL)并返回承载/访问令牌.我正在使用Thinktecture.IdentityModel.Client.OAuth2Client来处理登录并获取访问令牌,这一切都正常.

其他一些事情发生但现在我希望Web应用程序能够解码访问令牌以访问API上的声明集(特别是登录API后返回的用户ID).

我正在使用带有令牌端点的大量演示UseOAuthAuthorizationServerUseOAuthBearerAuthentication扩展方法,几乎​​开箱即用,但有一个自定义OAuthAuthorizationServerOptions.Provider来访问我自己的存储库.

我在两个应用程序上都有相同的MachineKey,但我不清楚如何解码令牌,虽然我知道我可能不得不使用该SecureDataFormat.Unprotect方法.

我在Web应用程序中最接近的尝试是:

Task<TokenResponse> response = client.RequestResourceOwnerPasswordAsync(model.Email, model.Password);

IDataProtector dataProtecter = Startup.DataProtectionProvider.Create("does this matter?");
TicketDataFormat ticketDataFormat = new TicketDataFormat(dataProtecter);
AuthenticationTicket ticket = ticketDataFormat.Unprotect(response.Result.AccessToken);
Run Code Online (Sandbox Code Playgroud)

使用Startup.DataProtectionProvider设置如下:

public partial class Startup
{
    internal static IDataProtectionProvider DataProtectionProvider { get; private set; }

    public void Configuration(IAppBuilder app)
    {
        DataProtectionProvider = app.GetDataProtectionProvider();
        this.ConfigureAuth(app);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的后退计划是提供一种API方法,在登录后返回我感兴趣的信息,但看起来过多,因为它构成了令牌中声明的一部分(据我了解).

我试图绕过JWT(我看过Thinktecture,微软的源代码和各种其他论坛),但不确定这是否有帮助(尽管声明在纯文本中可用我们很有用).我还没有找到允许使用基本身份验证登录并返回包含访问令牌的自定义JWT的示例.

无论如何,我希望这些信息和任何帮助都会受到赞赏...欢呼

access-token jwt oauth2client asp.net-mvc-5 asp.net-web-api2

9
推荐指数
1
解决办法
4207
查看次数

Spring Boot + 具有自定义提供程序的安全 OAuth2.0 客户端

我正在 Spring Boot + Security(版本 5)应用程序中为自定义 OAuth2 提供程序创建 OAuth2.0 客户端。

下面是application.properties包含所有配置的,并且在我的项目中没有额外的配置类。

spring.security.oauth2.client.registration.xxxxxxxxx.client-id=XXXXXXXXXX
spring.security.oauth2.client.registration.xxxxxxxxx.client-secret=XXXXXXXXXX
spring.security.oauth2.client.registration.xxxxxxxxx.scope=openid
spring.security.oauth2.client.registration.xxxxxxxxx.redirect-uri-template=http://localhost:8080/login/oauth2/code/xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.client-name=xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.provider=xxxxxxxxx
spring.security.oauth2.client.registration.xxxxxxxxx.client-authentication-method=basic
spring.security.oauth2.client.registration.xxxxxxxxx.authorization-grant-type=authorization_code

spring.security.oauth2.client.provider.xxxxxxxxx.authorization-uri=https://api.xxxxxxxxx.com/authorize
spring.security.oauth2.client.provider.xxxxxxxxx.token-uri=https://api.xxxxxxxxx.com/token
spring.security.oauth2.client.provider.xxxxxxxxx.user-info-uri=https://api.xxxxxxxxx.com/userinfo?schema=openid
spring.security.oauth2.client.provider.xxxxxxxxx.user-name-attribute=name
spring.security.oauth2.client.provider.xxxxxxxxx.user-info-authentication-method=header
Run Code Online (Sandbox Code Playgroud)

当我点击http://localhost:8080/它时,它会正确重定向到提供商的登录页面,成功登录后它会重定向回我的应用程序。

现在的问题是当它重定向时它会显示以下错误消息。 在此输入图像描述

我已经用谷歌搜索了这个错误,但没有得到任何正确的答案。此外,OAuth2 提供商没有共享此类 URL。

经过研究,我发现我需要设置以下属性。应该由Auth Provider 提供吗? spring.security.oauth2.client.provider.pepstores.jwk-set-uri

我在配置中到底缺少什么?

oauth-2.0 oauth2client spring-security-oauth2 spring-oauth2

9
推荐指数
1
解决办法
2万
查看次数

Oauth2.0适合第一方应用吗?

我正在用 Angular 开发 SPA 应用程序,对于实现身份验证和授权的正确方法有很多困惑。

首先,该应用程序是第一方应用程序,这意味着我正在开发授权服务器和资源服务器。

登录应用程序的用户必须拥有对其平台上资源的完全访问权限。

因此,我使用 OAuth2.0 来完成此操作,并且我对该协议的域以及安全问题有一些疑问。

第一个问题:

第一个问题是 OAuth 是否应该实际用于授权第一方应用程序。据我了解,这是一种委托协议,用于在用户同意的情况下授予第三方应用程序对平台上用户资源的受控访问权限。这如何适合第一方应用程序的环境?在这种情况下,应用程序应该获得一个访问令牌,其范围允许完全访问,对吗?

第二个问题:

由于这是一个单页应用程序,我无法在客户端存储秘密。因此,我选择使用 PKCE 的授权代码授予,这似乎适合管理这种情况。在这种情况下,我不会要求刷新令牌,但我只会检索访问令牌并使用静默检查来刷新它。我不想将刷新令牌不安全地存储在浏览器上。这个PKCE真的安全吗?该秘密是动态生成的,但攻击者最终可以使用相同的公共客户端 ID 创建一个系统并正确管理 PKCE,并最终获得一个访问令牌,在我的例子中,该令牌可以完全访问用户资源。

我将来可以允许第三方应用程序对我的应用程序资源进行受控访问,这也是我坚持使用 OAuth 的原因之一。

security oauth oauth2client spring-oauth2

9
推荐指数
1
解决办法
2746
查看次数

Django 1.7 google oauth2令牌验证失败

我正在尝试通过验证Google令牌来访问Django应用程序中的用户日历.虽然我已经跟踪了网上发现的几个迹象,但我仍然遇到了对我的回调函数(错误请求)的400错误代码响应.

views.py

# -*- coding: utf-8 -*-
import os

import argparse
import httplib2
import logging

from apiclient.discovery import build
from oauth2client import tools
from oauth2client.django_orm import Storage
from oauth2client import xsrfutil
from oauth2client.client import flow_from_clientsecrets

from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.core.urlresolvers import reverse
from django.contrib import auth
from django.contrib.auth.decorators import login_required
from django.conf import settings

from apps.tecnico.models import Credentials, Flow

CLIENT_SECRETS = os.path.join(
    os.path.dirname(__file__), '../../client_secrets.json')

@login_required
def index(request): …
Run Code Online (Sandbox Code Playgroud)

python django google-api oauth-2.0 oauth2client

8
推荐指数
2
解决办法
1314
查看次数

AttributeError:'module'对象没有属性'SignedJwtAssertionCredentials'

问题:我一直在使用Google的Python脚本示例将apk上传到Play商店并获取通过我的帐户发布的应用列表(list_apks.pyupload_apk.py).然而最近它开始打破.我试图通过这样做来更新类似的软件包google-api-python-client,但它没有帮助.oath2clientpip install --update packagename

日志:

这个如果在列出apk的时候:

Determining latest version for my.package.name...
error   25-Feb-2016 06:30:52    Traceback (most recent call last):
error   25-Feb-2016 06:30:52      File "list_apks.py", line 80, in <module>
error   25-Feb-2016 06:30:52        main()
error   25-Feb-2016 06:30:52      File "list_apks.py", line 46, in main
error   25-Feb-2016 06:30:52        credentials = client.SignedJwtAssertionCredentials(
error   25-Feb-2016 06:30:52    AttributeError: 'module' object has no attribute 'SignedJwtAssertionCredentials'
build   25-Feb-2016 06:30:52    Found latest APK version: 
build   25-Feb-2016 06:30:52    Generated …
Run Code Online (Sandbox Code Playgroud)

python android attributeerror oauth2client google-play-developer-api

8
推荐指数
1
解决办法
3592
查看次数

导入错误:没有名为 gspread 的模块

我正在尝试使用gspreadpython 中的库。我安装了lib,pip install gspread但是当我运行代码时:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://sreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('FILE_NAME.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open('Changelog').sheet1
print(wks.get_all_records())
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

File "stuff.py", line 1, in <module>
    import gspread
ImportError: No module named gspread
Run Code Online (Sandbox Code Playgroud)

当我在 python3 中运行它时,它没有给我任何导入错误。但那些:

File "stuff.py", line 8, in <module>
    gc = gspread.authorize(credentials)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gspread/__init__.py", line 38, in authorize
    client.login()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/gspread/client.py", line 51, in login
    self.auth.refresh(http)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/client.py", line 545, in refresh
    self._refresh(http)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/oauth2client/client.py", line 749, …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 python-3.x oauth2client gspread

7
推荐指数
1
解决办法
1万
查看次数

OAuth2RestTemplate中的代理配置

我需要使用由OAuth2保护的API.为此我使用OAuth2RestTemplate.但我得到以下错误:

java.net.ConnectException: Connection timed out: connect
Run Code Online (Sandbox Code Playgroud)

由于代理问题,这种情况正在发生.我知道如何在RestTemplate中设置代理:

 SimpleClientHttpRequestFactory clientHttpRequestFactory = new       SimpleClientHttpRequestFactory();
 Proxy proxy = new Proxy(Proxy.Type.HTTP, new      InetSocketAddress("Proxy host", 8080));
Run Code Online (Sandbox Code Playgroud)

clientHttpRequestFactory.setProxy(代理); RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);

我尝试为OAuth2RestTemplate设置的方式相同:

@Bean
public OAuth2RestOperations restTemplate(OAuth2ClientContext oauth2ClientContext) {
    OAuth2RestTemplate client =  new OAuth2RestTemplate(resource(), oauth2ClientContext);
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT));
    clientHttpRequestFactory.setProxy(proxy);
    client.setRequestFactory(clientHttpRequestFactory);
    return client;
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用并给出"连接超时"例外.发生这种情况是因为第一行OAuth2RestTemplate client = new OAuth2RestTemplate(resource(), oauth2ClientContext);尝试获取Access令牌,这意味着它还需要代理设置.如果我添加以下行,那么它的工作原理:

System.setProperty("https.proxyHost", "urproxy.com");
System.setProperty("https.proxyPort", "8080");
Run Code Online (Sandbox Code Playgroud)

但我不能使用System.setProperties("","")选项,因为我们没有权限在tomcat服务器上设置.

我研究过但在创建此对象时找不到任何在OAuth2RestTemplate中设置代理的方法.

任何帮助,将不胜感激.谢谢

proxy oauth2client spring-security-oauth2 oauth2

6
推荐指数
1
解决办法
3345
查看次数