wso2-extensions / identity-outbound-auth-oidc

Apache License 2.0
6 stars 108 forks source link

Add diagnostic logs to the authenticator #147

Closed sahandilshan closed 1 year ago

sahandilshan commented 1 year ago

Proposed changes in this pull request

Approach

image

Diagnostic logs will be covered the green-colored actions/validations of the authentication process.

  1. Authentication Request Validation Within each authenticator, the initiateAuthenticationRequest method houses the logic for this step. This triggers two diagnostic logs. The first log indicates the initialization of the authentication request, and the second log shows the authentication request has been successfully sent – whether it's a Success or marked Invalid.

  2. Validate Authentication Response The processAuthenticationResponse method handles authentication responses sent by the federated IDP. Once users are sent to the federated IDP page and complete the login, the authenticator receives an authentication response sent by the federated IDP, which this method manages. Just like the request validation, this step also generates two diagnostic logs. The first one marks the beginning of response validation, while the second one is only created if the authentication is successful. We've chosen not to include logs for authentication response failures for a couple of reasons:

    • Numerous potential failure scenarios across authenticators make adding logs for each too complicated and code-heavy.
    • With https://github.com/wso2/carbon-identity-framework/pull/4809, there's a common log in place that covers and reports authentication response failures caused by authenticators.

Additionally, there will be another diagnostic log that will get published from the canHandle() method of the authenticator. The canHandle method gets executed each time before the initiateAuthenticationRequest and processAuthenticationResponse get executed. This log is published as an internal log for our internal developers. The purpose of this log is to verify whether the auth request/response was passed into the authenticator to handle it.

I've also introduced a new protected method named getComponentId. This addition serves a specific purpose. The OpenIDAuthenticator class extends into other Authenticators like GitHub and Google. These extended Authenticators utilize the initiateAuthenticationRequest and processAuthenticationResponse methods from the OpenIDAuthenticator class. However, this can lead to diagnostic logs being attributed to the OIDC authenticator even when they're handled by the relevant Authenticator (with no change in the component ID of the logs). To address this, I've implemented the getComponentId method. This method returns the component ID. When each Authenticator (like Google or Github) overrides this method, the component ID in the logs gets adjusted accordingly. This ensures that the logs correctly reflect the handling Authenticator.

jenkins-is-staging commented 1 year ago

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

jenkins-is-staging commented 1 year ago

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

jenkins-is-staging commented 1 year ago

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

jenkins-is-staging commented 1 year ago

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