Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle Weibo Web OAuth #50

Closed
dourgulf opened this issue Sep 18, 2016 · 10 comments
Closed

How to handle Weibo Web OAuth #50

dourgulf opened this issue Sep 18, 2016 · 10 comments

Comments

@dourgulf
Copy link

dourgulf commented Sep 18, 2016

作者好, 首先感谢开源.
最近试用没有安装微博APP情况下的OAuth授权. 看了代码的基本原理是用一个webview直接打开"https://open.weibo.cn/oauth2/authorize?client_id", 当代理方法要跳转到我们的redirectURI的时候, 关闭webview.
但是, 没有看明白是怎么把授权的结果返回给APP的?包括授权状态,用户ID等信息.

@Limon-O-O
Copy link
Collaborator

public func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {}
在这个方法里面有一个请求,https://api.weibo.com/oauth2/access_token

@dourgulf
Copy link
Author

这个请求玩了之后是怎么触发结果给客户端的? 它的返回数据格式跟APP授权返回的数据格式一样的吗?

@dourgulf
Copy link
Author

哦, 看懂了
// App or Web: token & userID
guard let token = (OAuthInfo?["access_token"] ?? OAuthInfo?["accessToken"]) as? String, let userID = (OAuthInfo?["uid"] ?? OAuthInfo?["userID"]) as? String else {
return
}
这里判断不同的key?

@Limon-O-O
Copy link
Collaborator

在此fun removeWebView() 方法里面调用了 oauthCompletionHandler?() 闭包,直接回调出去,并没有处理微博返回的 JSON

@Limon-O-O
Copy link
Collaborator

因为渣浪iPadiPhone上面返回的JSON不一样...

@dourgulf
Copy link
Author

谢谢, 看懂了.
BTW: 作者是否有意向把这个功能提交给OpenShare?

@dourgulf
Copy link
Author

在iPad和iPhone上还不一样呀...., 哪, 还不得做各种兼容, 渣浪可以的....

@Limon-O-O
Copy link
Collaborator

哈哈,OC 我已经忘了怎么写了 😀....

@Limon-O-O
Copy link
Collaborator

我印象中最重要的 token 这个 key 是不同的,现在不知道统不统一了,你可以测试下

@dourgulf
Copy link
Author

好的, 我测试一下, 打算把你这块的功能提交回OpenShare~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants