End users often want to execute some random logic just before initiating the OAuth dance or right after it has been completed. Use cases include notifying an external system that a given owner ID has been successfully on-boarded, keeping activity logs, and so on.
The authorization process is triggered by hitting an automatically created endpoint, so the <oauth-authorization-code> child element has the before and after parameters.
These optional parameters specify the name of a <flow> to be invoked before or after the OAuth dance.
Before flow
The before flow will be executed just before the OAuth dance is started. The payload of the event sent to that flow will be an instance of AuthorizationCodeRequest, which is an immutable POJO that looks like this:
public interface AuthCodeRequest {
/**
* @return The id of the user being authenticated
*/
String getResourceOwnerId();
/**
* @return The scopes that were requested
*/
Optional<String> getScopes();
/**
* @return The OAuth state that was sent
*/
Optional<String> getState();
/**
* @return The external callback url that the user configured or {@link Optional#empty()} if none was provided
*/
Optional<String> getExternalCallbackUrl();
}
In this flow, the user can perform any custom logic as needed. In particular, the user can set flow variables (see After Flow).
After Flow
The after flow is executed right after the access token has been received and stored. This flow is executed with an event that is equivalent to what came out of the before flow (or a blank event if no before flow was defined), except for the payload,
which is replaced by the same AuthorizationCodeState object that is injected in the ConnectionProvider. However, any variables previously set are still there (or will be empty if no before flow was defined).