【问题标题】:What redirect uri should I use (OAuth 2.0)?我应该使用什么重定向 uri(OAuth 2.0)?
【发布时间】:2012-11-01 17:58:45
【问题描述】:

我为谷歌 API 控制台注册了我的应用程序。我得到了我的客户端密码、客户端 ID 和两个重定向 uris

//● urn:xxxxxxx:oob

//● http://localhostxxxxxx

当然,我使用这些项目并成功向谷歌请求令牌。但是当我点击授权按钮时(比如“你想授权这个应用程序吗?”是的), 出现两个响应。

如果我使用 urnxxxxxx,我会收到“无法完成操作。(com.google.HTTPStatus 错误 404。)”。

//Or If I use http://localhostxxxxxxxxxxxxx and click Yes button, then nothing    
happens.

接下来我该怎么做? (以下代码供谷歌阅读器使用。)

#import "MasterViewController.h"

#import "DetailViewController.h"

#import "GTMOAuth2Authentication.h"

#import "GTMOAuth2ViewControllerTouch.h"

#import "GTMOAuth2WindowController.h"

static NSString *const kKeychainItemName = @"Greader";


@interface MasterViewController () {
    NSMutableArray *_objects;
}
@end

@implementation MasterViewController


- (IBAction)authentication:signInToGoogle:(id)sender;

{}

- (GTMOAuth2Authentication * ) authForGoogle
{ 
    NSString * url_string = @"http://www.google.com/reader/api/";
    NSURL * tokenURL = [NSURL URLWithString:url_string];

    NSString * redirectURI = @"xxxxoob";
    GTMOAuth2Authentication * auth;
    auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"reader"
                                                         tokenURL:tokenURL
                                                      redirectURI:redirectURI
                                                         clientID:@"xxxxx"
                                                     clientSecret:@"xxxx"];

    auth.scope = @"http://www.google.com/reader/api/";
    return auth;
}


- (void)signInToGoogle

{
    GTMOAuth2Authentication * auth = [self authForGoogle];
    NSString* auth_string = @"https://accounts.google.com/o/oauth2/auth";
    NSURL * authURL = [NSURL URLWithString:auth_string];

    GTMOAuth2ViewControllerTouch * viewController;
    viewController = [[GTMOAuth2ViewControllerTouch alloc]initWithAuthentication:auth
                                                             authorizationURL:authURL
                                                             keychainItemName:kKeychainItemName
                                                                     delegate:self
                                                             finishedSelector:@selector(viewController:finishedWithAuth:error:)];
    [self.navigationController pushViewController:viewController animated:YES];
}

【问题讨论】:

    标签: objective-c oauth


    【解决方案1】:

    您应该首先了解 oAuth。

    通常,第一个链接是授权流程 - 您调用它并获取代码。 第二个 URL 是使用从前一个 URL 获得的代码获取令牌。

    解释如何使用 oAuth 超出了此处的范围,但您可以阅读和学习很多地方。

    【讨论】:

    • 感谢您的回答。我正在学习 OAuth,但仍然只是初学者。但是....我已经了解了一些关于 OAuth 的知识并且有一个大问题。您介意在您方便的时候回答我的问题吗?
    • 我了解到当我的应用程序将用户重定向到授权页面时,我必须发布“客户端密码”“范围”和“重定向 uri 才能在用户授权我的应用程序后使用。我选择了@“xxxxoob”作为重定向uri(正如你所说,我认为授权流程工作时需要这样做。)但是我仍然有错误“com.google.HTTPStatus error 404”除了我使用错误的uri之外是否有可能?
    • 如果得到404,相信问题出在授权页面的URL上。尝试重新检查它,以确保它是好的。您可以打开一个专门针对此问题的新线程,并在那里粘贴更多信息(例如您尝试调用的 URL 等)顺便说一句,如果我的第一个答案有帮助,请随时善待并将其标记为正确的(就在下方"0") :-)
    猜你喜欢
    • 2019-11-10
    • 1970-01-01
    • 2012-10-23
    • 2014-07-08
    • 1970-01-01
    • 2021-11-21
    • 2012-07-05
    • 2016-03-23
    • 2014-04-26
    相关资源
    最近更新 更多