Skip to content

Instantly share code, notes, and snippets.

@skiph
Created October 24, 2017 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skiph/dec5fbc0a6a622deb9f46400082969d4 to your computer and use it in GitHub Desktop.
Save skiph/dec5fbc0a6a622deb9f46400082969d4 to your computer and use it in GitHub Desktop.
private void startServiceConfig() {
Log.i(TAG, "Starting service config");
String discoveryEndpoint = app.getString(R.string.discovery_endpoint);
if (discoveryEndpoint.trim().length() == 0 || !URLUtil.isValidUrl(discoveryEndpoint)) {
Log.i(TAG, "Using static service config");
AuthorizationServiceConfiguration serviceConfig =
new AuthorizationServiceConfiguration(
Uri.parse(app.getString(R.string.authorization_endpoint)),
Uri.parse(app.getString(R.string.token_endpoint)));
authState = new AuthState(serviceConfig);
userInfoUrl = app.getString(R.string.user_info_endpoint);
finishServiceConfig();
} else {
Log.i(TAG, "Using discovery service config");
Uri discoveryUri = Uri.parse(discoveryEndpoint);
loginListener.onEvent(AuthRepo.this, AUTH_SERVICE_DISCOVERY_START);
AuthorizationServiceConfiguration.fetchFromUrl(discoveryUri, this::finishServiceDiscovery);
}
}
private void finishServiceDiscovery(AuthorizationServiceConfiguration config,
AuthorizationException ex) {
if (config == null) {
failLogin(new AuthException("Failed to retrieve authorization service discovery document"));
return;
}
authState = new AuthState(config);
AuthorizationServiceDiscovery discovery = config.discoveryDoc;
userInfoUrl = discovery.getUserinfoEndpoint().toString();
loginListener.onEvent(AuthRepo.this, AUTH_SERVICE_DISCOVERY_FINISH);
finishServiceConfig();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment