我完全按照https://developer.chrome.com/extensions/tut_oauth进行操作,但是我被困在
https://developer.chrome.com/extensions/tut_oauth#identity_permission
在执行扩展后,在没有获取令牌的情况下出现以下错误:
Unchecked runtime.lastError while running identity.getAuthToken:
OAuth2 request failed: Service responded with error: 'bad request'
Run Code Online (Sandbox Code Playgroud)
请指出此错误的可能原因是什么。
google-chrome-extension google-oauth google-oauth2 google-sheets-api
我正在制作一个java命令行应用程序,该应用程序打包在一个使用某些Google API的JAR文件中.
我需要从私钥"Credentials.p12"设置GoogleCredential对象.
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("xxxxx@developer.gserviceaccount.com")
.setServiceAccountScopes(Arrays.asList(DirectoryScopes.ADMIN_DIRECTORY_GROUP, DirectoryScopes.ADMIN_DIRECTORY_USER, DirectoryScopes.ADMIN_DIRECTORY_ORGUNIT))
.setServiceAccountUser(emailAccount)
//THE CODE BELOW IS IMPORTANT: I need to change this
.setServiceAccountPrivateKeyFromP12File(new File("Credentials.p12"))
.build();
directory = new Directory.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("My Cmd App")
.build();
Run Code Online (Sandbox Code Playgroud)
现在我能够使它工作,但文件"Credentials.p12"位于打包的JAR文件之外.
如何使用JAR内部的p12文件使其工作?
从这个文档中,我认为我可以使用的唯一其他替代方法是使用PrivateKey对象的方法变体.我正在考虑使用InputStream从类路径获取p12文件:
InputStream is = this.getClass().getResourceAsStream("Credentials.p12");
Run Code Online (Sandbox Code Playgroud)
我完全不知道该怎么做.
在您回答之前,请确保您有使用Google OAuth2库的经验.并且,请不要将资源复制到临时文件中:如果出于某种原因,Credential.p12的单数版本应该保留在JAR中.
我正在尝试使用远程API连接到AppEngine实例,如下所示:
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = ".../path/to/key"
remote_api_stub.ConfigureRemoteApiForOAuth(
server.encode('ascii'), path, secure=True
)
Run Code Online (Sandbox Code Playgroud)
当path/to/key点在谷歌云(测试版)创建了一个JSON文件,API管理器- >凭证- >添加凭据- >服务帐户." 权限"面板中的"可以编辑"服务帐户.
当我运行它时,我在控制台上收到类似这样的错误,对应于401(在App Engine日志查看器中报告):
File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 768, in ConfigureRemoteApiForOAuth
rpc_server_factory=rpc_server_factory)
File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 835, in ConfigureRemoteApi
app_id = GetRemoteAppIdFromServer(server, path, rtok)
File "/usr/local/share/app-engine-python/google/appengine/ext/remote_api/remote_api_stub.py", line 569, in GetRemoteAppIdFromServer
response = server.Send(path, payload=None, **urlargs)
File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 258, in Send
NeedAuth()
File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 234, in NeedAuth
RaiseHttpError(url, response_info, response, 'Too many auth attempts.')
File "/usr/local/share/app-engine-python/google/appengine/tools/appengine_rpc_httplib2.py", line 85, in RaiseHttpError
raise urllib2.HTTPError(url, response_info.status, msg, … 我使用以下脚本来集成谷歌身份验证
//google auth code
gapi.load('auth2', function() {//load in the auth2 api's, without it gapi.auth2 will be undefined
gapi.auth2.init(
{
client_id: '1063305095705-k68gpfhi46tbu6kv8e8tidc751hte5pb.apps.googleusercontent.com'
}
);
var GoogleAuth = gapi.auth2.getAuthInstance();//get's a GoogleAuth instance with your client-id, needs to be called after gapi.auth2.init
$scope.onLogInButtonClick=function(){//add a function to the controller so ng-click can bind to it
GoogleAuth.signIn().then(function(response){//request to sign in
console.log(response);
console.log(response.wc.wc);
console.log(response.wc.hg);
console.log(response.wc.Ph);
});
};
});
Run Code Online (Sandbox Code Playgroud)
我试图在其他一些应用程序中使用它并收到以下错误: -
gapi.auth2.ExternallyVisibleError: gapi.auth2 has been initialized with
different options. Consider calling gapi.auth2.getAuthInstance()
instead of gapi.auth2.init().
Run Code Online (Sandbox Code Playgroud)
我也包括在内
<script …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用OAuth2授权我的用户.我目前正在使用以下库:https://github.com/p2/OAuth2
let oauth2 = OAuth2CodeGrant(settings: [
"client_id": "my-id",
"authorize_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://www.googleapis.com/oauth2/v3/token",
"scope": "profile", // depends on the API you use
"redirect_uris": ["com.TestAuthorizeApp:/oauth2Callback"],
])
//let oauth2 = OAuth2CodeGrant(settings: settings)
oauth2.onAuthorize = { parameters in
print("Did authorize with parameters: \(parameters)")
}
oauth2.onFailure = { error in // `error` is nil on cancel
if let error = error {
print("Authorization went wrong: \(error)")
}
}
oauth2.authConfig.authorizeEmbedded = false
oauth2.authorize()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它在浏览器中加载谷歌,我能够登录.然后它询问我在范围内声明的权限,并且工作正常.我点击确定打开,它将我重定向回我的应用程序.
但是,当我再次运行此代码时,我希望访问令牌已存储在密钥链中.然而,这似乎不起作用.
我查看了源代码并找到了以下检查:tryToObtainAccessTokenIfNeeded总是返回false.这意味着我再次获取页面,我需要单击"允许".
我想知道是否有人可以帮我弄清楚为什么它不能保存钥匙串中的任何东西.这是否意味着用户并未真正进行身份验证?
谢谢.
===
编辑
oauth2.verbose …
我使用dektrium/yii2-user(在一个项目上)和yiisoft/yii2-authclient(在另一个项目上)通过Google帐户登录.前段时间一切都还好,但我想在最后一个作曲家更新之后发生了一些变化,现在我得到一个错误:当尝试打开登录页面时,"类yii\authclient\clients\GoogleOAuth不存在".有没有人有同样的问题或知道什么是错的?谢谢
我的网站过去没有使用Google oauth登录的问题.突然间我收到了上述错误.
需要获得授权才能从Google Play开发者API获取信息。
我知道如何使用Postman进行此操作,但是实现授权要麻烦得多(重定向URL,处理重定向等),这些步骤就是您已经在Google Developer API Console中设置auth数据的步骤。
1.) GET https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://www.myurl.com/oauth2callback&client_id=1234567890.apps.googleusercontent.com
2.) get code which was sent to redirect url.
3.) POST https://accounts.google.com/o/oauth2/token
with
grant_type:authorization_code
code:[the code I got before]
client_id:1234567890.apps.googleusercontent.com
client_secret:[my client secret]
4.) Invoke GET https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/subscriptions/subscriptionId/tokens/token
with:
Scope: https://www.googleapis.com/auth/androidpublisher
and:
access_token as query parameter I got before.
Run Code Online (Sandbox Code Playgroud)
现在,我要以编程方式完成所有这些操作。显然不是那么容易。我以为Google API客户端库会有所帮助,但我看不到这些库如何为我的用例提供帮助。
例如,像GoogleAuthorizationCodeFlow之类的类在请求时希望有一个用户ID,但现在不一定要有一个用户ID,因此我想知道如何以一种干净的方式使用此API。
有没有一种干净的方法可以通过一些API来更轻松/以编程方式处理OAuth2.0,以访问Google Play开发者API?否则,我必须手动实现它。
google-api google-oauth google-oauth-java-client google-oauth2
现在,在不更改我的代码或配置的情况下,谷歌要求用户每次尝试对我的应用进行身份验证时都向用户授予权限。即使用户已经磨碎了访问权限,范围也没有改变。
我没有收到任何错误,登录正常,只是现在每次都会出现询问权限的Google对话框。
要初始化google,请使用带有“ https://www.googleapis.com/auth/plus.profile.emails.read ”作为范围的gapi.auth2.init。为了请求访问,我使用auth2.grantOfflineAccess。
我还在Google帐户中签入了具有访问权限的应用,并且该应用已在其中成功注册。
还有其他人看到过这个问题吗?还是不知道Google是否改变了他们处理权限的方式?
这是我发布的上一个问题/答案的后续内容(如何使用Google电子邮件设置API和OAuth2 for Apps脚本库为Google Apps域中的用户设置电子邮件签名),但我正在创建一个新的问题,因为电子邮件设置API已被弃用,现在流程明显不同.
作为G Suite域的管理员,您如何使用Gmail API 以编程方式通过Google Apps脚本设置域中用户的电子邮件签名?
email google-apps google-apps-script gmail-api google-oauth2
google-oauth2 ×10
google-oauth ×3
google-api ×2
email ×1
gapi ×1
gmail-api ×1
google-apps ×1
ios ×1
java ×1
keychain ×1
oauth-2.0 ×1
oauth2 ×1
php ×1
private-key ×1
python ×1
swift ×1
yii2 ×1
yii2-user ×1