We are using OAuth2 authorization to fetch an access token after logging in on the ESRI portal, and using that token later to authenticate basemaps.
Once the login page is dismissed we return to our mobile app with a redirect URL and store the token.
The token is requested via the Rest API described here: https://developers.arcgis.com/rest/users-groups-and-items/authorize.htm. We are using response_type='code' and no referer therefore.
Later, we did the following:
... {
let challengeHandler = EsriAuthenticationChallengeHandler.shared
challengeHandler.delegate = self
AGSAuthenticationManager.shared().delegate = challengeHandler
let oAuthConfiguration = AGSOAuthConfiguration(portalURL: portalURI,
clientID: clientID,
redirectURL: redirectURL)
AGSAuthenticationManager.shared().oAuthConfigurations.add(oAuthConfiguration)
}
class EsriAuthenticationChallengeHandler: NSObject, AGSAuthenticationManagerDelegate {
static let shared = EsriAuthenticationChallengeHandler()
func authenticationManager(_ authenticationManager: AGSAuthenticationManager, didReceive challenge: AGSAuthenticationChallenge) {
guard challenge.type == .oAuth else { return }
challenge.continue(with: AGSCredential(token: esriToken, referer: nil))
}
}The token is correct, double checked that, but still nothing happens, the basemap itself is not rendered.
If I simply remove the `didReceive challenge:` method, it correctly displays the alert to require the username and password.
Am I missing something? Any help is appreciated.