什么是重定向 URI?它如何适用于 OAuth2.0 的 iOS 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13281084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's a redirect URI? how does it apply to iOS app for OAuth2.0?
提问by David T.
Beginner programmer here, please pardon ignorance & explanations will be really nice :)
这里的初学者程序员,请原谅无知,解释会非常好:)
I've tried to read the tutorials for a certain OAuth 2.0 service, but I don't understand this redirect URI... in my particular context, let's say I'm trying to build an iPhone app that uses OAuth 2.0 for some service. I have an App ID that was generated, but i need to provide some sort of redirect URI to generate the API key.
我试图阅读某个 OAuth 2.0 服务的教程,但我不明白这个重定向 URI... . 我有一个生成的 App ID,但我需要提供某种重定向 URI 来生成 API 密钥。
Is this a URL that I'm supposed to host somewhere myself?? As the name suggests, I would think that the redirect URL is supposed to "redirect" someone somewhere. My only guess is that it's the URL a user is redirected to after they log in to the service.
这是一个我应该自己托管在某个地方的 URL 吗?顾名思义,我认为重定向 URL 应该将某人“重定向”到某个地方。我唯一的猜测是,这是用户登录服务后重定向到的 URL。
However, even if that assumption is correct, I don't understand one other thing - how can my app be opened again after I've sent them to the browser for the user login?
但是,即使该假设是正确的,我也不明白另一件事 - 在我将它们发送到浏览器以供用户登录后,如何再次打开我的应用程序?
回答by David T.
Read this:
读这个:
http://www.quora.com/OAuth-2-0/How-does-OAuth-2-0-work
http://www.quora.com/OAuth-2-0/How-does-OAuth-2-0-work
or an even simpler but quick explanation:
或者更简单但快速的解释:
http://agileanswer.blogspot.se/2012/08/oauth-20-for-my-ninth-grader.html
http://agileanswer.blogspot.se/2012/08/oauth-20-for-my-ninth-grader.html
The redirect URI is the callback entry point of the app. Think about how OAuth for Facebook works - after end user accepts permissions, "something" has to be called by Facebook to get back to the app, and that "something" is the redirect URI. Furthermore, the redirect URI should be different than the initial entry point of the app.
重定向 URI 是应用程序的回调入口点。想一想 Facebook 的 OAuth 是如何工作的——在最终用户接受权限后,Facebook 必须调用“某物”才能返回应用程序,而“某物”就是重定向 URI。此外,重定向 URI 应与应用程序的初始入口点不同。
The other key point to this puzzle is that you could launch your app from a URL given to a webview. To do this, i simply followed the guide on here:
这个难题的另一个关键点是您可以从提供给 webview 的 URL 启动您的应用程序。为此,我只是按照此处的指南进行操作:
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
and
和
http://inchoo.net/mobile-development/iphone-development/launching-application-via-url-scheme/
http://inchoo.net/mobile-development/iphone-development/launching-application-via-url-scheme/
note: on those last 2 links, "http://" works in opening mobile safari but "tel://" doesn't work in simulator
注意:在最后 2 个链接上,“http://”在打开移动 safari 时有效,但“tel://”在模拟器中不起作用
in the first app, I call
在第一个应用程序中,我调用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"secondApp://"]];
In my second app, I register "secondApp" (and NOT "secondApp://") as the name of URL Scheme, with my company as the URL identifier.
在我的第二个应用程序中,我将“secondApp”(而不是“secondApp://”)注册为 URL Scheme 的名称,并将我的公司注册为 URL 标识符。
回答by Reckoner
Take a look at OAuth 2.0 playground.You will get an overview of the protocol.It is basically an environment(like any app) that shows you the steps involved in the protocol.
看看 OAuth 2.0 playground。您将获得协议的概述。它基本上是一个环境(就像任何应用程序一样),向您展示协议中涉及的步骤。
回答by Dhirender Tyagi
redirected uri is the location where the user will be redirected after successfully login to your app. for example to get access token for your app in facebook you need to subimt redirected uri which is nothing only the app Domain that your provide when you create your facebook app.
重定向的 uri 是用户在成功登录到您的应用后将被重定向的位置。例如,要在 facebook 中为您的应用程序获取访问令牌,您需要提交重定向的 uri,这不仅仅是您在创建 facebook 应用程序时提供的应用程序域。
回答by Kunal Khanna
If you are using Facebook SDK, you don't need to bother yourself to enter anything for redirect URI on the app management page of facebook. Just setup a URL scheme for your iOS app. The URL scheme of your app should be a value "fbxxxxxxxxxxx" where xxxxxxxxxxx is your app id as identified on facebook. To setup URL scheme for your iOS app, go to info tab of your app settings and add URL Type.
如果您使用的是 Facebook SDK,则无需费心在 facebook 的应用管理页面上为重定向 URI 输入任何内容。只需为您的 iOS 应用程序设置一个 URL 方案。您的应用程序的 URL 方案应该是一个值“fbxxxxxxxxxxx”,其中 xxxxxxxxxxx 是您在 Facebook 上标识的应用程序 ID。要为您的 iOS 应用设置 URL 方案,请转到应用设置的信息选项卡并添加 URL 类型。