How i can fetch Accesstoken and fetch user details when using Appauth?
Nobody has claimed this yet.
- Dominant language
- Objective-C
- Stars
- 2k
- Forks
- 867
- Avg merge
- 4d 48m
- Merged PRs (30d)
- 1
Description
I am using Xcode 12.1, iOS 12.4 in the simulator
As per the documents and GitHub demo, I am implementing code and do research to fetch token but after redirection to the webpage, my code is not return anything or retrieve data when the user login successfully.
Below is the code on Login button :
guard let issuer = URL(string: kIssuer) else {
self.logMessage("Error creating URL for : \(kIssuer)")
return
}
self.logMessage("Fetching configuration for issuer: \(issuer)")
startAuthFlow()
// discovers endpoints
OIDAuthorizationService.discoverConfiguration(forIssuer: issuer) { configuration, error in
guard let config = configuration else {
self.logMessage("Error retrieving discovery document: \(error?.localizedDescription ?? "DEFAULT_ERROR")")
self.setAuthState(nil)
return
}
print("Got configuration: \(config)")
if let clientId = kClientID {
self.doAuthWithAutoCodeExchange(configuration: config, clientID: clientId, clientSecret: nil)
}
self.logMessage("Got configuration: \(config)")
}
self.loadState()
I'm using the below function for an authentication request
func doAuthWithAutoCodeExchange(configuration: OIDServiceConfiguration, clientID: String, clientSecret: String?) {
guard let redirectURI = URL(string: kRedirectURI) else {
print("Error creating URL for : \(kRedirectURI)")
return
}
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
print("Error accessing AppDelegate")
return
}
// builds authentication request
let request = OIDAuthorizationRequest(configuration: configuration,
clientId: clientID,
clientSecret: clientSecret,
scopes: [OIDScopeOpenID],
redirectURL: redirectURI,
responseType: OIDResponseTypeCode,
additionalParameters: nil)
// performs authentication request
print("Initiating authorization request with scope: \(request.scope ?? "DEFAULT_SCOPE")")
appDelegate.currentAuthorizationFlow = OIDAuthState.authState(byPresenting: request, presenting: self) { authState, error in
if let authState = authState {
self.setAuthState(authState)
print("Got authorization tokens. Access token")
self.getUserInfo()
}else{
self.setAuthState(nil)
print("Authorization error: \(error?.localizedDescription ?? "DEFAULT_ERROR")")
}
}
}
Below is my token request code but not calling any function after login successfully.
func makeTokenRequest(completion: @escaping (OIDAuthState?, Error?) -> Void) {
guard let tokenExchangeRequest = self.authState?.lastAuthorizationResponse.tokenExchangeRequest() else {
print("Error creating access token request.")
return
}
print("Making token request with: ", tokenExchangeRequest)
OIDAuthorizationService.perform(tokenExchangeRequest) {
response, error in
if let response = response {
print("Received token response with access token: ", response.accessToken ?? "")
} else {
print("Error making token request: \(error?.localizedDescription ?? "")")
}
self.authState?.update(with: response, error: error)
completion(self.authState, error)
}
}
How can I retrieve an access token and user data please help me through this?
Thank you.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with doAuthWithAutoCodeExchange and the AppDelegate currentAuthorizationFlow handling, then compare the redirect path with the GitHub demo mentioned in the issue. Trace whether the authState callback is reached after login and whether makeTokenRequest receives a response; done means the callback completes with an access token and the requested user data path is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- authentication, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100