Reputation: 1
I am working on a project which strictly requires GitHub OAuth app authentication. I am redirecting the user from my app to GitHub using this link:
GET https://github.com/login/oauth/authorize
what I think should happen is for GitHub to ask for GitHub account of the user and then open my app using the redirection Url I give in the body of the first request. That is exactly what is happening but how can I get that redirection Url from GitHub because right now I am using AppDelegate but it is not being activated.
class AppDelegate: NSObject, UIApplicationDelegate {
var loginViewModel: LoginViewModel?
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
guard url.scheme == "my_scheme" else { return false }
guard let code = getQueryStringParameter(url: url.absoluteString, param: "code"), let state = getQueryStringParameter(url: url.absoluteString, param: "state"), state == loginViewModel?.authService.state else { return false }
Task {
if let viewModel = loginViewModel {
let success = await viewModel.authService.fetchAndStoreAccessToken(code: code)
if success {
viewModel.loginState = .loggedIn
} else {
viewModel.loginState = .loggedOut
print("Failed to fetch and store the access token.")
}
}
}
return true
}
How to get it triggered?
I thought it is due to the dependancy of loginViewModel but after I debugged the whole program I uncovered that AppDelegate is never activated.
Upvotes: 0
Views: 28