All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fun.fengwk.convention4j.oauth2.server.service.mode.ImplicitMode Maven / Gradle / Ivy

There is a newer version: 1.1.14
Show newest version
package fun.fengwk.convention4j.oauth2.server.service.mode;

import fun.fengwk.convention4j.common.util.NullSafe;
import fun.fengwk.convention4j.oauth2.server.manager.OAuth2ClientManager;
import fun.fengwk.convention4j.oauth2.server.manager.OAuth2SubjectManager;
import fun.fengwk.convention4j.oauth2.server.model.OAuth2Client;
import fun.fengwk.convention4j.oauth2.server.model.OAuth2Token;
import fun.fengwk.convention4j.oauth2.server.model.context.AuthorizeContext;
import fun.fengwk.convention4j.oauth2.server.repo.OAuth2TokenRepository;
import fun.fengwk.convention4j.oauth2.share.constant.OAuth2Mode;
import fun.fengwk.convention4j.oauth2.share.constant.ResponseType;
import fun.fengwk.convention4j.oauth2.share.constant.TokenType;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;

/**
 * @author fengwk
 */
public class ImplicitMode extends BaseOAuth2AuthorizeService {

    public ImplicitMode(OAuth2ClientManager clientManager,
                           OAuth2SubjectManager subjectManager,
                           OAuth2TokenRepository oauth2TokenRepository) {
        super(clientManager, subjectManager, oauth2TokenRepository);
    }

    @Override
    protected ResponseType getResponseType() {
        return OAuth2Mode.IMPLICIT.getResponseType();
    }

    @Override
    protected URI generateAuthorizeUri(AuthorizeContext context,
                                       OAuth2Client client,
                                       UriComponentsBuilder redirectUriBuilder,
                                       String subjectId) {
        String ssoId = getSsoId(context);
        OAuth2Token oauth2TokenDTO = generateToken(subjectId, context.getScope(), client, ssoId);
        return buildAuthorizeURI(redirectUriBuilder, oauth2TokenDTO, context.getState(), client);
    }

    private URI buildAuthorizeURI(UriComponentsBuilder redirectUriBuilder,
                                  OAuth2Token oauth2Token,
                                  String state,
                                  OAuth2Client client) {
        return redirectUriBuilder
            .queryParam("accessToken", oauth2Token.getAccessToken())
            .queryParam("tokenType", NullSafe.map(oauth2Token.getTokenType(), TokenType::getCode))
            .queryParam("expiresIn",oauth2Token.accessTokenExpiresIn(client.getAccessTokenExpireSeconds()))
            .queryParam("state", state)
            .build().toUri();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy