Ошибка OAuthSwift -3 при попытке подключения к API - PullRequest
0 голосов
/ 12 апреля 2019

Я пытаюсь использовать OAuth 2 с API, используя OAuthSwift. Может быть, я могу получить причину токена В AppDelegate я могу напечатать URL своего токена (OAuthSwift.handle (url: url))

Но в View Controller я не смог сохранить токен в связке ключей. Я получаю ошибку

Invalidating cache
The operation couldn’t be completed. (OAuthSwiftError error -3.)

Мой код:

let oauthswift = OAuth2Swift(
    consumerKey:    "5xxxxxxxxxxxxxxxxxxxxx",
    consumerSecret: "4xxxxxxxxxxxxxxxxxxxxx",
    authorizeUrl:    "https://api.orange.com/oauth/authorize",
    accessTokenUrl: "https://api.orange.com/oauth/token",
    responseType:   "code"
)

@IBAction func onTappedSyncButton(_ sender: UIButton) {
    let keychain = Keychain(service: "myapp-token")
    oauthswift.accessTokenBasicAuthentification = true

    if keychain["oauthToken"] == nil {
    let handle = oauthswift.authorize(
            withCallbackURL: URL(string: "my-orangesdk-app://orangehub")!,
            scope: "default",
            state:"",
            success: { credential, response, parameters in
                //Here, I couldn't print and save keychain
                print(credential.oauthToken)
                keychain["oauthToken"] = credential.oauthToken
            },
            failure: { error in
                print(error.localizedDescription)                  
            })
    }
}

AppDelegate:

func application(_ app: UIApplication,
                 open url: URL,
                 options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    if (url.host == "orangeapi") {
        OAuthSwift.handle(url: url)
        print(url)
        //Here, I could see token.
    }
    return true
}
...