Search in sources :

Example 6 with JakartaRequestAdapter

use of com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter in project solon by noear.

the class AuthorizationController method authorizeGet.

@Get
@Mapping("authorize")
public void authorizeGet(Context ctx, HttpServletRequest request) throws IOException {
    // authorize
    IdsResponse<String, String> idsResponse = this.authorizationEndpoint.authorize(new JakartaRequestAdapter(request));
    ctx.redirect(idsResponse.getData());
}
Also used : JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 7 with JakartaRequestAdapter

use of com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter in project ddd by EricFoxz.

the class Oauth2Controller method renderAuth.

@RequestMapping("/login/jai")
@SneakyThrows
public ModelAndView renderAuth(HttpServletRequest request, HttpServletResponse response) {
    Oauth2Strategy oauth2Strategy = new Oauth2Strategy(applicationOauth2Service, new JapConfig());
    OAuthConfig config = new OAuthConfig();
    config.setPlatform("jai").setState(IdUtil.fastSimpleUUID()).setClientId("xx").setClientSecret("xx").setCallbackUrl("http://sso.jap.com:8443/oauth2/login/jai").setAuthorizationUrl("xx").setTokenUrl("xx").setUserinfoUrl("xx").setScopes(new String[] { "read", "write" }).setResponseType(Oauth2ResponseType.CODE).setGrantType(Oauth2GrantType.AUTHORIZATION_CODE);
    JapResponse japResponse = oauth2Strategy.authenticate(config, new JakartaRequestAdapter(request), new JakartaResponseAdapter(response));
    if (!japResponse.isSuccess()) {
        return new ModelAndView(new RedirectView("/?error=" + URLUtil.encode(japResponse.getMessage())));
    }
    if (japResponse.isRedirectUrl()) {
        return new ModelAndView(new RedirectView((String) japResponse.getData()));
    } else {
        // 登录成功,需要对用户数据进行处理
        // ...
        System.out.println(japResponse.getData());
        return new ModelAndView(new RedirectView("/"));
    }
}
Also used : JapConfig(com.fujieid.jap.core.config.JapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) Oauth2Strategy(com.fujieid.jap.oauth2.Oauth2Strategy) JapResponse(com.fujieid.jap.core.result.JapResponse) OAuthConfig(com.fujieid.jap.oauth2.OAuthConfig) JakartaResponseAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter) SneakyThrows(lombok.SneakyThrows) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JakartaRequestAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter)7 Mapping (org.noear.solon.annotation.Mapping)6 JakartaResponseAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter)5 JapResponse (com.fujieid.jap.core.result.JapResponse)3 Get (org.noear.solon.annotation.Get)3 Post (org.noear.solon.annotation.Post)3 HttpServletRequestWrapperImpl (com.fujieid.jap.solon.HttpServletRequestWrapperImpl)2 JapConfig (com.fujieid.jap.core.config.JapConfig)1 OAuthConfig (com.fujieid.jap.oauth2.OAuthConfig)1 Oauth2Strategy (com.fujieid.jap.oauth2.Oauth2Strategy)1 SocialConfig (com.fujieid.jap.social.SocialConfig)1 SneakyThrows (lombok.SneakyThrows)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1