Exemplo n.º 1
0
 private Response sendImplicitGrantResponse(
     AuthorizationRequest authReq, AccessToken accessToken) {
   String uri = authReq.getRedirectUri();
   String fragment =
       String.format(
               "access_token=%s&token_type=bearer&expires_in=%s&scope=%s",
               accessToken.getToken(),
               accessToken.getExpiresIn(),
               StringUtils.join(authReq.getGrantedScopes(), ','))
           + appendStateParameter(authReq);
   if (authReq.getClient().isIncludePrincipal()) {
     fragment += String.format("&principal=%s", authReq.getPrincipal().getDisplayName());
   }
   return Response.seeOther(UriBuilder.fromUri(uri).fragment(fragment).build())
       .cacheControl(cacheControlNoStore())
       .header("Pragma", "no-cache")
       .build();
 }
Exemplo n.º 2
0
 private AccessToken createAccessToken(AuthorizationRequest request, boolean isImplicitGrant) {
   Client client = request.getClient();
   long expireDuration = client.getExpireDuration();
   long expires =
       (expireDuration == 0L ? 0L : (System.currentTimeMillis() + (1000 * expireDuration)));
   String refreshToken =
       (client.isUseRefreshTokens() && !isImplicitGrant) ? getTokenValue(true) : null;
   AuthenticatedPrincipal principal = request.getPrincipal();
   AccessToken token =
       new AccessToken(
           getTokenValue(false),
           principal,
           client,
           expires,
           request.getGrantedScopes(),
           refreshToken);
   return accessTokenRepository.save(token);
 }