Skip to content

Commit

Permalink
Handle OpenID claims parameter in auth requests on Android (MaikuB#292)
Browse files Browse the repository at this point in the history
The claims parameter is an optional part of the OpenID standard when making an authorization request (see https://openid.net/specs/openid-connect-core-1_0.html#ClaimsParameter).

Currently, this parameter is not supported by the Flutter interface layer, so the only way to pass it is via the additionalParameters argument when constructing an AuthorizationRequest. This, however, leads to the following error on Android:

```
E/AndroidRuntime( 7453): java.lang.IllegalArgumentException: Parameter claims is directly supported via the authorization request builder, use the builder method instead
```

This commit allows specifying the claims via additionalParameters and having this be correctly handled on Android, in order to be compatible with the `AuthorizationRequest.Builder` method.
  • Loading branch information
garry-jeromson authored Feb 7, 2022
1 parent 76c9865 commit d01e09e
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import net.openid.appauth.TokenResponse;
import net.openid.appauth.connectivity.DefaultConnectionBuilder;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -51,6 +54,7 @@ public class FlutterAppauthPlugin implements FlutterPlugin, MethodCallHandler, P
private static final String TOKEN_ERROR_CODE = "token_failed";
private static final String END_SESSION_ERROR_CODE = "end_session_failed";
private static final String NULL_INTENT_ERROR_CODE = "null_intent";
private static final String INVALID_CLAIMS_ERROR_CODE = "invalid_claims";

private static final String DISCOVERY_ERROR_MESSAGE_FORMAT = "Error retrieving discovery document: [error: %s, description: %s]";
private static final String TOKEN_ERROR_MESSAGE_FORMAT = "Failed to get token: [error: %s, description: %s]";
Expand Down Expand Up @@ -333,6 +337,18 @@ private void performAuthorization(AuthorizationServiceConfiguration serviceConfi
authRequestBuilder.setUiLocales(additionalParameters.get("ui_locales"));
additionalParameters.remove("ui_locales");
}

if(additionalParameters.containsKey("claims")){
try {
final JSONObject claimsAsJson = new JSONObject(additionalParameters.get("claims"));
authRequestBuilder.setClaims(claimsAsJson);
additionalParameters.remove("claims");
}
catch (JSONException ex) {
finishWithError(INVALID_CLAIMS_ERROR_CODE, ex.getLocalizedMessage(), getCauseFromException(ex));
return;
}
}
authRequestBuilder.setAdditionalParameters(additionalParameters);
}

Expand Down

0 comments on commit d01e09e

Please sign in to comment.