本文介绍了Google OAuth 2.0 invalid_client 未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码通过 OAuth 2.0 授权 Google+

I used this code to authorize Google+ via OAuth 2.0

oauthswift = OAuth2Swift(消费者密钥:984813079630-f828a92sqtl5lgumd4kgp9i30bs9og09.apps.googleusercontent.com",消费者秘密:AIzaSyD13MBv78yWIjl4TX9jOOT9AWuEkYdVSPQ",authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",accessTokenUrl: "https://www.googleapis.com/oauth2/v4/token",响应类型:代码")

    let handle = oauthswift.authorize(
            withCallbackURL: URL(string: "com.googleusercontent.apps.984813079630-f828a92sqtl5lgumd4kgp9i30bs9og09:/oauth")!,
            scope: "profile", state:"GOOGLE",
            success: { credential, response, parameters in
                print(credential.oauthToken)
                // Do your request
            },
            failure: { error in
                print(error.localizedDescription)
                print((error as OAuthSwiftError).errorUserInfo)
            }
    )

但结果总是失败

无法完成操作.(OAuthSwiftError 错误 -11.)[请求":https://www.googleapis.com/oauth2/v4/token, "error": 错误域=NSURLErrorDomain 代码=401invalid_client 未经授权"UserInfo={Response-Body={ "error": "invalid_client","error_description": "未经授权" } ,NSErrorFailingURLKey=https://www.googleapis.com/oauth2/v4/token,响应头={缓存控制"=私有,最大年龄=0";内容编码"= gzip;内容长度"= 81;内容类型"=应用程序/json;字符集=UTF-8";日期 = "星期四,2017 年 6 月 15 日 04:25:10 GMT";Expires = "星期四,2017 年 6 月 15 日 04:25:10 GMT";服务器 = GSE;Vary = "Origin, X-Origin";"Www-Authenticate" = "Bearer realm=\"https://accounts.google.com/\"";"alt-svc" = "quic=\":443\"; ma=2592000; v=\"38,37,36,35\"";x-content-type-options"= nosniff;"x-frame-options" = SAMEORIGIN;x-xss-protection"=1;模式=块";}, OAuthSwiftError.response= { URL:https://www.googleapis.com/oauth2/v4/token } { 状态代码:401,标题{缓存控制"=私有,最大年龄=0";内容编码"= gzip;内容长度"= 81;内容类型"=应用程序/json;字符集=UTF-8";日期 = "星期四,2017 年 6 月 15 日 04:25:10 GMT";Expires = "星期四,2017 年 6 月 15 日 04:25:10 GMT";服务器 = GSE;Vary = "Origin, X-Origin";"Www-Authenticate" = "Bearer realm=\"https://accounts.google.com/\"";"alt-svc" = "quic=\":443\"; ma=2592000; v=\"38,37,36,35\"";x-content-type-options"= nosniff;"x-frame-options" = SAMEORIGIN;x-xss-protection"=1;模式=块";} }, OAuthSwiftError.response.data=<7b0a2022 6572726f 72223a20 22696e76616c6964 5f636c69 656e7422 2c0a2022 6572726f 725f6465 736372697074696f 6e223a20 22556e61 7574686f 72697a65 64220a7d 0a>,NSLocalizedDescription=invalid_client 未经授权}]

你能更正吗?

推荐答案

您必须使用 "your.bundle.id:/oauth2Callback"

来自演示 OAuthSwift 的评论:

Commentary from demo OAuthSwift:

对于谷歌,redirect_uri 应该匹配你的这个语法:your.bundle.id:/oauth2Callback

在 plist 中定义一个 url schem:your.bundle.id

In plist define a url schem with: your.bundle.id

经过这些更改后,我仍然遇到了这个问题.找到解决方案:

After these changes, I still had this problem. Found solution:

我用一个空字符串删除了 customerSecret 然后......它起作用了.

希望能帮到你我上面的回答!

I hope to help you with my answer above!

这篇关于Google OAuth 2.0 invalid_client 未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 23:55
查看更多