目标C:如何从Web浏览器获取访问令牌到cocoa app?(Objective C: How to get access token from web browser to cocoa app?)

请让我详细说明我想做什么。

我想做的事?

我创建了一个将用户文件上传到用户的Onedrive的可可应用程序,并通过在Safari中启动访问令牌URL来执行此操作。

https://login.live.com/oauth20_authorize.srf?client_id={APPLICATIONID}&scope=wl.signin+wl.offline_access+onedrive.readwrite&response_type=token&redirect_uri= https://login.live.com/oauth20_desktop.srf

问题

现在的问题是我将如何从safari中检索访问令牌到我的可可应用程序?

简而言之:如何在Cocoa Application中获得一个驱动器访问令牌?

请帮忙。 非常感谢

Please let me elaborate what I am trying to do.

What I want to do?

I am creating a cocoa application that uploads an user files to user's Onedrive and in order to do that I am requesting for an Access token by launching the access token URL in Safari.

https://login.live.com/oauth20_authorize.srf?client_id={APPLICATIONID}&scope=wl.signin+wl.offline_access+onedrive.readwrite&response_type=token&redirect_uri= https://login.live.com/oauth20_desktop.srf

Problem

Now the problem is how will I retrieve the access token from safari to my cocoa app?

In short: How to get one drive access token in Cocoa Application?

Please help. Many thanks

最满意答案

为了在本地应用程序上获取访问令牌,您需要遵循以下步骤:

登录到dev.onedrive.com并在移动或桌面客户端应用程序选项中选中YES 在这里输入图像描述 在您的应用程序中使用浏览器控件并加载访问令牌验证页面 为浏览器控件添加URL更改事件 无论何时您获得一个以https://login.live.com/oauth20_desktop.srf开头并具有#和access_token变量的url,这意味着您的应用程序已经接收到来自用户的访问权限。 如果用户点击NO(不提供访问权限),那么您将获得一个以https://login.live.com/oauth20_desktop.srf?lc=1033#error=access_denied开头的URL

注意:这个想法非常简单。 您需要监控URL更改并相应地执行任务。

PS:请记住,本地应用的重定向网址将为https://login.live.com/oauth20_desktop.srf

In order get access token on Local application you will need to follow given below steps:

Login to dev.onedrive.com and check YES on Mobile or desktop client app option enter image description here Take a browser control in you application and load the access token verify page Add a URL change event for browser control Whenever you get a url starting with https://login.live.com/oauth20_desktop.srf that has a # and access_token variable than it means you application has received the access from a user. In case user clicks on NO(not providing access) then you will get a url starting with https://login.live.com/oauth20_desktop.srf?lc=1033#error=access_denied

Note: The idea is very simple. You will need to monitor URL changes and do the task accordingly.

P.S: Keep in mind that the redirect URL for local apps will be https://login.live.com/oauth20_desktop.srf

更多推荐