Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Heimdall Swift验证每个请求失败_Ios_Swift_Oauth_Swift2 - Fatal编程技术网

Ios Heimdall Swift验证每个请求失败

Ios Heimdall Swift验证每个请求失败,ios,swift,oauth,swift2,Ios,Swift,Oauth,Swift2,我正在使用Heimdall for oauth2访问和验证我自己的api,但我似乎无法验证我的第二个请求。有人看到我做错了什么吗。我几乎可以肯定,获得访问令牌的第一个请求是正确的。因为我最终成功了 我的代码: @IBAction func loginTapped(sender : AnyObject) { let username = InputUsername.text let password = InputPassword.text let tokenURL =

我正在使用Heimdall for oauth2访问和验证我自己的api,但我似乎无法验证我的第二个请求。有人看到我做错了什么吗。我几乎可以肯定,获得访问令牌的第一个请求是正确的。因为我最终成功了

我的代码:

@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:")
        }
    })
}
但结果是:

<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;
} }
{URL:https://[my domain]/auth/info}{status code:401,headers{
“接受范围”=字节;
年龄=0;
“缓存控制”=“无存储,专用”;
“内容长度”=78;
“内容类型”=“应用程序/json”;
日期=“2015年8月16日星期日14:17:29 GMT”;
Pragma=“无缓存”;
服务器=nginx;
Via=“1.1清漆”;
“Www Authenticate”=“Bearer realm=”Service\”,error=”access\u denied\”,error\u description=”OAuth2 authentication required\”;
“x缓存”=未命中;
“x-debug-token”=6eea58;
“x-debug-token-link”=“/_profiler/6eea58”;
“x-清漆”=1051959467;
} }

问题似乎在于我自己的API在承载身份验证方面采用了不同的方法