什么是重定向 URI?它如何适用于 OAuth2.0 的 iOS 应用程序? [英] What's a redirect URI? how does it apply to iOS app for OAuth2.0?

查看:28
本文介绍了什么是重定向 URI?它如何适用于 OAuth2.0 的 iOS 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的程序员初学者,请原谅无知&解释会非常好:)

Beginner programmer here, please pardon ignorance & explanations will be really nice :)

我尝试阅读某个 OAuth 2.0 服务的教程,但我不明白这个重定向 URI...在我的特定上下文中,假设我正在尝试构建一个使用 OAuth 2.0 的 iPhone 应用程序对于某些服务.我有一个生成的 App ID,但我需要提供某种重定向 URI 来生成 API 密钥.

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.

这是一个我应该自己托管的网址吗??顾名思义,我认为重定向 URL 应该将某人重定向"到某个地方.我唯一的猜测是,这是用户登录服务后重定向到的 URL.

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.

然而,即使这个假设是正确的,我也不明白另一件事——我的应用程序在我将它们发送到浏览器以供用户登录后如何再次打开?

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?

推荐答案

阅读:

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

重定向 URI 是应用的回调入口点.想一想 Facebook 的 OAuth 是如何工作的——在最终用户接受权限后,Facebook 必须调用某物"才能返回应用程序,而某物"就是重定向 URI.此外,重定向 URI 应与应用的初始入口点不同.

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.

这个难题的另一个关键点是您可以从提供给网络视图的 URL 启动您的应用.为此,我只需按照此处的指南进行操作:

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:

http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

http://inchoo.net/mobile-development/iphone-development/launching-application-via-url-scheme/

注意:在最后 2 个链接上,http://"在打开移动 safari 时有效,但tel://"在模拟器中不起作用

在第一个应用程序中,我调用

in the first app, I call

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"secondApp://"]];

在我的第二个应用程序中,我将secondApp"(而不是secondApp://")注册为 URL Scheme 的名称,并将我的公司作为 URL 标识符.

In my second app, I register "secondApp" (and NOT "secondApp://") as the name of URL Scheme, with my company as the URL identifier.

这篇关于什么是重定向 URI?它如何适用于 OAuth2.0 的 iOS 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆