EDIT:
It is fixed The issue was that I used a wrong WKWebview (not the one on the storyboard) Changing that fix my issue
Hello there,
is there someone who can help me with the OAuth2 library in swift I'm doing that to handle the end of OAuth
appDelegate.oauth2!.afterAuthorizeOrFail = { authParameters, error in
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let myString = formatter.string(from: appDelegate.oauth2!.accessTokenExpiry!)
print("t \(appDelegate.oauth2!.accessToken)")
print("td \(myString)")
//login me here with oauth2.accessToken
}
In this block I want to log into my website with an url like that : "http://my-website.com/authme.php?token=\(oauth2!.accessToken!)"
I've try webview.load and no success. If I open the URL in another method everything work like a charm
I think it is due to the fact that afterAuthorizeOrFail seems to be called in background
Here is how afterAuthorizeOrFail is called didFail and didAuthorize which only differences are the arguments of the function in those methods
public final func didFail(with error: OAuth2Error?) {
var finalError = error
if let error = finalError {
logger?.debug("OAuth2", msg: "\(error)")
}
else {
finalError = OAuth2Error.requestCancelled
}
callOnMainThread() {
self.didAuthorizeOrFail?(nil, finalError)
self.didAuthorizeOrFail = nil
self.internalAfterAuthorizeOrFail?(true, finalError)
self.afterAuthorizeOrFail?(nil, finalError)
}
}
Here is the source file with this method https://github.com/p2/OAuth2/blob/master/Sources/Base/OAuth2Base.swift
and callOnMainThread is that:
public func callOnMainThread(_ callback: (() -> Void)) {
if Thread.isMainThread {
callback()
}
else {
DispatchQueue.main.sync(execute: callback)
}
}
Here is the source file with this method https://github.com/p2/OAuth2/blob/master/Sources/Base/OAuth2Requestable.swift
And here is how I do the request
let requrl=URL(string: "http://my-website.com/authme.php?token=\(oauth2!.accessToken!)")
do{
let request = try URLRequest(url: requrl!,method: .post)
self.webView!.load(request)
}catch let error {
DispatchQueue.main.async {
print("ERROR loading site \(error)")
}
}
Thanks in advance