我正在尝试用OAuth2.0授权我的用户。我当前正在使用以下库:https://github.com/p2/OAuth2。
这是我的代码:
let oauth2 = OAuth2CodeGrant(settings: [
"client_id": "******", //ID from Fitbit
"client_secret": "***************************", //Secret from Fitbit
"authorize_uri": "https://www.fitbit.com/oauth2/authorize",
"token_uri": "https://api.fitbit.com/oauth2/token",
"redirect_uris": ["http://google.com/"],
"scope": "profile settings activity nutrition heartrate location nutrition profile settings sleep social weight",
"secret_in_body": true,
"keychain": false,
] as OAuth2JSON)
func startAuthorization() {
oauth2.logger = OAuth2DebugLogger(.trace)
oauth2.authorize() { authParameters, error in
if let params = authParameters {
print("Authorized! Access token is in `oauth2.accessToken`")
print("Authorized! Additional parameters: \(params)")
}
else {
print("Authorization was cancelled or went wrong: \(error)") // error will not be nil
}
}
}
[Debug] OAuth2: Starting authorization
[Debug] OAuth2: No access token, checking if a refresh token is available
[Debug] OAuth2: I don't have a refresh token, not trying to refresh
[Debug] OAuth2: Opening authorize URL in system browser: https://www.fitbit.com/oauth2/authorize?state=35701F98&response_type=code&scope=profile+settings+activity+nutrition+heartrate+location+nutrition+profile+settings+sleep+social+weight&redirect_uri=http%3A%2F%2Fgoogle.com%2F&client_id=******
不确定这是否能帮到你,但演示应用程序中有一些fitbit的示例。它最后一次更新是在2个月前,所以应该在swift 3中。但如果不是的话,我会提前道歉。
位于此处:https://github.com/OAuthSwift/OAuthSwift/blob/master/Demo/Common/ViewController.swift
他们有fitbit和fitbit 2的代码。
搜索//mark:fitbit
编辑:我的坏,错误的图书馆…
我的答案是这个图书馆:
https://github.com/OAuthSwift/OAuthSwift
关于ios - Fitbit OAuth2.0 token 请求(Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41632824/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |