Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify apple authenticator to enable federation flow in API based Authentication and Nonce validation #9

Merged

Conversation

ZiyamSanthosh
Copy link
Contributor

@ZiyamSanthosh ZiyamSanthosh commented Jun 30, 2024

This PR includes the below given changes

  • Enables API based authentication with federation flow for Apple authenticator. This supports both Native mode and Redirection mode.
  • Enable nonce validation for apple authenticator.

Related issue:

Merge the PR after merging the below given PR and bumping the oidc version:

Sample Responses

  1. Initial /authorize request
{
    "flowId": "44f86b73-55fd-4ec5-8571-c7f4049d3c07",
    "flowStatus": "INCOMPLETE",
    "flowType": "AUTHENTICATION",
    "nextStep": {
        "stepType": "MULTI_OPTIONS_PROMPT",
        "authenticators": [
            {
                "authenticatorId": "R29vZ2xlT0lEQ0F1dGhlbnRpY2F0b3I6R29vZ2xl",
                "authenticator": "Google",
                "idp": "Google",
                "metadata": {
                    "i18nKey": "authenticator.google"
                }
            },
            {
                "authenticatorId": "QXBwbGVPSURDQXV0aGVudGljYXRvcjpBcHBsZQ",
                "authenticator": "Apple",
                "idp": "Apple",
                "metadata": {
                    "i18nKey": "authenticator.apple"
                }
            }
        ]
    },
    "links": [
        {
            "name": "authentication",
            "href": "https://wso2is.com:9443/oauth2/authn",
            "method": "POST"
        }
    ]
}
  1. /authn request (Native mode)
{
    "flowId": "44f86b73-55fd-4ec5-8571-c7f4049d3c07",
    "flowStatus": "INCOMPLETE",
    "flowType": "AUTHENTICATION",
    "nextStep": {
        "stepType": "AUTHENTICATOR_PROMPT",
        "authenticators": [
            {
                "authenticatorId": "QXBwbGVPSURDQXV0aGVudGljYXRvcjpBcHBsZQ",
                "authenticator": "Apple",
                "idp": "Apple",
                "metadata": {
                    "i18nKey": "authenticator.apple",
                    "promptType": "INTERNAL_PROMPT",
                    "additionalData": {
                        "clientId": "com.asgupgrade.stage",
                        "scope": "email name"
                    }
                },
                "requiredParams": [
                    "accessToken",
                    "idToken"
                ]
            }
        ]
    },
    "links": [
        {
            "name": "authentication",
            "href": "https://wso2is.com:9443/oauth2/authn",
            "method": "POST"
        }
    ]
}
  1. /authn request (Redirection mode)
{
    "flowId": "44f86b73-55fd-4ec5-8571-c7f4049d3c07",
    "flowStatus": "INCOMPLETE",
    "flowType": "AUTHENTICATION",
    "nextStep": {
        "stepType": "AUTHENTICATOR_PROMPT",
        "authenticators": [
            {
                "authenticatorId": "QXBwbGVPSURDQXV0aGVudGljYXRvcjpBcHBsZQ",
                "authenticator": "Apple",
                "idp": "Apple",
                "metadata": {
                    "i18nKey": "authenticator.apple",
                    "promptType": "REDIRECTION_PROMPT",
                    "additionalData": {
                        "state": "43fa600f-0ad3-4170-80e8-d8e615d59e09,OIDC",
                        "redirectUrl": "https://appleid.apple.com/auth/authorize?response_type=code&state=43fa600f-0ad3-4170-80e8-d8e615d59e09%2COIDC&redirect_uri=https%3A%2F%2Fgoogle.com&client_id=com.asgupgrade.stage&scope=email%20name&response_mode=form_post"
                    }
                },
                "requiredParams": [
                    "code",
                    "state"
                ]
            }
        ]
    },
    "links": [
        {
            "name": "authentication",
            "href": "https://wso2is.com:9443/oauth2/authn",
            "method": "POST"
        }
    ]
}

Related links:
[1] https://developer.apple.com/documentation/authenticationservices/asauthorizationopenidrequest/nonce

Sample JWT Payload from apple IDP

{
  "iss": "https://appleid.apple.com",
  "aud": "com.asgupgrade.stage",
  "exp": 1720100111,
  "iat": 1720013711,
  "sub": "001094.77fd79fb64a1413398438254b1a28e64.0535",
  "nonce": "f9945071-859e-4d2a-a6e4-5b435f16d109",
  "at_hash": "LfD82O14Te81Z_jqY6fAuQ",
  "email": "ziyam@wso2.com",
  "email_verified": true,
  "auth_time": 1720013689,
  "nonce_supported": true
}

@CLAassistant
Copy link

CLAassistant commented Jun 30, 2024

CLA assistant check
All committers have signed the CLA.

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/9734468257

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/9734468257
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/9734468257

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/9743477163

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/9743477163
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/9743477163

Thumimku
Thumimku previously approved these changes Jul 2, 2024
Copy link

@Thumimku Thumimku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -145,8 +151,13 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, HttpSer
String clientId = authenticatorProperties.get(OIDCAuthenticatorConstants.CLIENT_ID);
String authorizationEP = getAuthorizationServerEndpoint(authenticatorProperties);
String callbackUrl = getCallbackUrl(authenticatorProperties);
String state = getStateParameter(context, authenticatorProperties);
if (Boolean.parseBoolean((String) context.getProperty(IS_API_BASED))) {
callbackUrl = resolveCallBackURLForAPIBasedAuthFlow(context);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we have line 153 as the else block of this if?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can have getCallbackUrl method in this class and define this logic there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 9f2bc6f

@@ -145,8 +151,13 @@ protected void initiateAuthenticationRequest(HttpServletRequest request, HttpSer
String clientId = authenticatorProperties.get(OIDCAuthenticatorConstants.CLIENT_ID);
String authorizationEP = getAuthorizationServerEndpoint(authenticatorProperties);
String callbackUrl = getCallbackUrl(authenticatorProperties);
String state = getStateParameter(context, authenticatorProperties);
if (Boolean.parseBoolean((String) context.getProperty(IS_API_BASED))) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this IS_API_BASED property is set in the context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why can't we use the same constant defined in the framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This concern was addressed with 9f2bc6f

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/9772703024

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/9773189192

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/9772703024
Status: cancelled

protected String getScope(Map<String, String> authenticatorProperties) {

String scopes = authenticatorProperties.get(IdentityApplicationConstants.Authenticator.OIDC.SCOPES);
return scopes.replace(",", " ").replace("+", " ");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a null check here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also lets take the separators to constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was addressed in both 1a9f83d and 84cbc2f

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/9773189192
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/9773189192

* @param context Authentication context.
* @return Callback URL.
*/
private String getCallBackURL(AuthenticationContext context, Map<String, String> authenticatorProperties) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was addressed in 1a9f83d

@ZiyamSanthosh ZiyamSanthosh changed the title Modify apple authenticator to enable federation flow in API based Authentication Modify apple authenticator to enable federation flow in API based Authentication and Nonce validation Jul 4, 2024
pamodaaw
pamodaaw previously approved these changes Jul 4, 2024
@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/9789383875

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/9789383875
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/9789383875

@ZiyamSanthosh ZiyamSanthosh merged commit 9fa9386 into wso2-extensions:main Jul 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants