Search in sources :

Example 1 with Federation

use of com.authlete.jaxrs.server.federation.Federation in project java-oauth-server by authlete.

the class FederationEndpoint method initiation.

@GET
@Path("initiation/{federationId}")
public Response initiation(@Context HttpServletRequest req, @PathParam("federationId") String federationId) {
    // Get the Federation instance that corresponds to the federation ID.
    Federation federation = getFederation(federationId);
    // Generate a state and a code verifier.
    String state = new State().getValue();
    String verifier = new CodeVerifier().getValue();
    // Put them in the session so that callback() can use them later.
    putToSession(req, KEY_STATE, state);
    putToSession(req, KEY_VERIFIER, verifier);
    // Build an authentication request that conforms to OpenID Connect.
    URI authenticationRequest = buildAuthenticationRequest(federation, state, verifier);
    // authentication request to the authorization endpoint.
    return redirectTo(authenticationRequest);
}
Also used : CodeVerifier(com.nimbusds.oauth2.sdk.pkce.CodeVerifier) Federation(com.authlete.jaxrs.server.federation.Federation) State(com.nimbusds.oauth2.sdk.id.State) URI(java.net.URI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Federation

use of com.authlete.jaxrs.server.federation.Federation in project java-oauth-server by authlete.

the class FederationEndpoint method callback.

@GET
@Path("callback/{federationId}")
public Response callback(@Context HttpServletRequest req, @PathParam("federationId") String federationId) {
    // Authentication response from the OpenID Provider.
    URI authenticationResponse = getFullUri(req);
    // Get the Federation instance that corresponds to the federation ID.
    Federation federation = getFederation(federationId);
    // Data used to render the authorization page.
    AuthzPageModel model = getAuthzPageModel(req);
    // "state" and "code_verifier" which were generated in initiation().
    String state = takeFromSession(req, KEY_STATE);
    String verifier = takeFromSession(req, KEY_VERIFIER);
    // Ensure that 'state' is available.
    ensureState(state);
    // Communicate with the OpenID Provider to get information about the user.
    UserInfo userInfo = getUserInfo(federation, authenticationResponse, state, verifier, model);
    // Register the user into this server (or overwrite the existing info).
    User user = registerUser(federation, userInfo);
    // Make the user login.
    makeUserLogin(req, user);
    // Go back to the authorization page.
    return authorizationPage(model, user, null);
}
Also used : User(com.authlete.common.types.User) Federation(com.authlete.jaxrs.server.federation.Federation) UserInfo(com.nimbusds.openid.connect.sdk.claims.UserInfo) URI(java.net.URI) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Federation (com.authlete.jaxrs.server.federation.Federation)2 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 User (com.authlete.common.types.User)1 State (com.nimbusds.oauth2.sdk.id.State)1 CodeVerifier (com.nimbusds.oauth2.sdk.pkce.CodeVerifier)1 UserInfo (com.nimbusds.openid.connect.sdk.claims.UserInfo)1