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);
}
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);
}
Aggregations