Learn about what OAuth is and how to implement it using ASWebAuthenticationSession.
This is a companion discussion topic for the original entry at https://www.kodeco.com/19364429-implementing-oauth-with-aswebauthenticationsession
Learn about what OAuth is and how to implement it using ASWebAuthenticationSession.
Hi Felipe! Thanks for the nice tutorial. I have a question about ASWebAuthenticationSession on watchOS, I found the token can not be obtained on watch os since the callback closure is not called. (and the web view does not dismiss after correct login info is entered) .
let authenticationSession = ASWebAuthenticationSession(
url: signInURL,
callbackURLScheme: callbackURLScheme) { [weak self] callbackURL, error in
// Code will be added here next!
}
I think it is caused by callbackURLScheme not set correctly. If I close the web view the callback is called. Do you know how to set URL scheme on watch os, or other hints to fix the issue. Thanks!
In the final project NetworkRequest.swift line 176,
else if let object = try? JSONDecoder().decode(T.self, from: data)
spent some time to find out why this line can not decode the User. Finally I find that my dummy Github account has no name. I would suggest catch the exception to make it easier to debug.
Usually, for efficiency and to focus on the topics at hand, we might not get super detailed with error-handling.
I do agree, however, that for your project you likely want to wrap that code in a do-catch block and print out any exceptions or errors thrown during parsing.