我能夠使用LinkedIn SDK快速獲取LinkedIn LinkedIn帳戶的訪問令牌。如何使用Stormpath驗證此登錄信息?LinkedIn登錄Stormpath
[更新]
設APIURL = 「https://api.stormpath.com/v1/applications/LI_APPLICATION_ID /帳戶」
func sendRequestWithJSON(accessToken:String)
{
let json = [ "providerData" : ["providerId": "linkedin", "accessToken": accessToken] ]
do {
let jsonData = try NSJSONSerialization.dataWithJSONObject(json, options: .PrettyPrinted)
let username = STORMPATH_API_KEY_ID
let password = STORMPATH_API_KEY_SECRET
let loginString = NSString(format: "%@:%@", username, password)
let loginData: NSData = loginString.dataUsingEncoding(NSUTF8StringEncoding)!
let base64LoginString = loginData.base64EncodedDataWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
// create post request
let url = NSURL(string: APIURL)!
let request = NSMutableURLRequest(URL: url)
request.HTTPMethod = "POST"
// insert json data to the request
request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.HTTPBody = jsonData
let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ data, response, error in
if error != nil{
print("Error -> \(error)")
return
}
do {
let result = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? [String:AnyObject]
print("Result -> \(result)")
} catch {
print("Error -> \(error)")
}
}
task.resume()
//return task
} catch {
print(error)
}
}
我傳遞的accessToken從LinkedIn到上述功能取得,但它返回以下結果:
[「message」:需要認證,「status」:401,「code」:401,「developerMessage」:A必須使用有效的API密鑰進行驗證。「moreInfo」:http://www.stormpath.com/docs/quickstart/connect]
我在做什麼?
[iOS linkedin認證]的可能重複(http://stackoverflow.com/questions/28491280/ios-linkedin-authentication) – JAL
我不認爲它是重複的。鏈接的問題是詢問關於vanilla LinkedIn登錄,而這個問題是關於Stormpath支持的應用程序。 –