ios - Heimdall Swift authenticate each request failure -
i using heimdall https://github.com/rheinfabrik/heimdall.swift oauth2 access , authenticate own api seems can't authenticate second request. see thing doing wrong. sure first request access token right. because end in success case.
my code:
@ibaction func logintapped(sender : anyobject) { let username = inputusername.text let password = inputpassword.text let tokenurl = nsurl(string: "https://[my-domain]/oauth/v2/token")! var identifier = "my-id" var secret = "my-secret" let credentials = oauthclientcredentials(id: identifier, secret: secret) let heimdall = heimdall(tokenurl: tokenurl, credentials: credentials) heimdall.requestaccesstoken(username: username, password: password) { result in switch result { case .success: self.calluserinfo(heimdall) case .failure(let error): println("failure: \(error.description)") } } } func calluserinfo(heimdall: heimdall) { let urlpath = "https://my-domain/auth/info" let url: nsurl = nsurl(string: urlpath)! let session = nsurlsession.sharedsession() var request = nsmutableurlrequest(url: url) heimdall.authenticaterequest(request, completion: { result in switch result { case .success: let task = session.datataskwithrequest(request) { data, response, error in let json = json(data) println(response.description) } task.resume() case .failure(let error): println("failure:") } }) }
but result is:
<nshttpurlresponse: 0x7fd82a265ab0> { url: https://[my-domain]/auth/info } { status code: 401, headers { "accept-ranges" = bytes; age = 0; "cache-control" = "no-store, private"; "content-length" = 78; "content-type" = "application/json"; date = "sun, 16 aug 2015 14:17:29 gmt"; pragma = "no-cache"; server = nginx; via = "1.1 varnish"; "www-authenticate" = "bearer realm=\"service\", error=\"access_denied\", error_description=\"oauth2 authentication required\""; "x-cache" = miss; "x-debug-token" = 6eea58; "x-debug-token-link" = "/_profiler/6eea58"; "x-varnish" = 1051959467; } }
seems problem own api has different approach on bearer authentication
Comments
Post a Comment