Search in sources :

Example 1 with SocialConfig

use of com.fujieid.jap.social.SocialConfig in project solon by noear.

the class SocialController method redirect.

/**
 * 第三方跳转方法
 */
@Get
@Mapping("/social/{platform}")
public Object redirect(Context ctx, HttpServletRequest request, HttpServletResponse response, String platform, String next, String code, String state) throws IllegalAccessException {
    // 验证 二次回调地址 是否合法
    if (next == null) {
        // 如果没指定回调地址,可能是第三方回调的结果
        next = (String) this.cacheService.get(this.getKey(state));
        // 如果 Callback 所属的 State 已过期
        if (next == null) {
            throw new IllegalStateException();
        } else {
            // 填入缺失的 next 参数
            ctx.paramSet("next", next);
        }
    } else {
        if (!this.validNext(next)) {
            throw new IllegalAccessException();
        }
    }
    // 构建 社会化登录 Payload
    SocialConfig socialConfig = new SocialConfig().setPlatform(platform).setState(UuidUtils.getUUID()).setJustAuthConfig(this.japProperties.getCredentials().get(platform));
    // 将 State -> Callback 存入缓存
    this.cacheService.store(this.getKey(socialConfig.getState()), next, 300);
    // 请求登录
    JapResponse japResponse = this.socialStrategy.authenticate(socialConfig, new JakartaRequestAdapter(new HttpServletRequestWrapperImpl(ctx, request)), new JakartaResponseAdapter(response));
    return this.simpleResponse(ctx, japResponse);
}
Also used : HttpServletRequestWrapperImpl(com.fujieid.jap.solon.HttpServletRequestWrapperImpl) JakartaRequestAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter) JapResponse(com.fujieid.jap.core.result.JapResponse) SocialConfig(com.fujieid.jap.social.SocialConfig) JakartaResponseAdapter(com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter) Get(org.noear.solon.annotation.Get) Mapping(org.noear.solon.annotation.Mapping)

Example 2 with SocialConfig

use of com.fujieid.jap.social.SocialConfig in project solon by noear.

the class FixedSocialStrategy method authenticate.

@Override
public JapResponse authenticate(AuthenticateConfig config, JapHttpRequest request, JapHttpResponse response) {
    SocialConfig socialConfig = null;
    try {
        this.checkAuthenticateConfig(config, SocialConfig.class);
        socialConfig = (SocialConfig) config;
    } catch (JapException e) {
        return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
    }
    if (socialConfig.isBindUser()) {
        return this.bind(config, request, response);
    }
    // !!! 取消 Session 校验 !!!
    // JapUser sessionUser = this.checkSession(request, response);
    // if (null != sessionUser) {
    // return JapResponse.success(sessionUser);
    // }
    AuthRequest authRequest = null;
    try {
        authRequest = Reflect.on(this).call("getAuthRequest", config).get();
    } catch (JapException e) {
        return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
    }
    String source = socialConfig.getPlatform();
    AuthCallback authCallback = Reflect.on(this).call("parseRequest", request).get();
    if (Reflect.on(this).call("isCallback", source, authCallback).get()) {
        try {
            return Reflect.on(this).call("login", request, response, source, authRequest, authCallback, (SocialFunc) this::loginSuccess).get();
        } catch (JapUserException e) {
            return JapResponse.error(e.getErrorCode(), e.getErrorMessage());
        }
    }
    // If it is not a callback request, it must be a request to jump to the authorization link
    String url = authRequest.authorize(socialConfig.getState());
    return JapResponse.success(url);
}
Also used : AuthRequest(me.zhyd.oauth.request.AuthRequest) JapException(com.fujieid.jap.core.exception.JapException) AuthCallback(me.zhyd.oauth.model.AuthCallback) SocialConfig(com.fujieid.jap.social.SocialConfig) JapUserException(com.fujieid.jap.core.exception.JapUserException)

Aggregations

SocialConfig (com.fujieid.jap.social.SocialConfig)2 JapException (com.fujieid.jap.core.exception.JapException)1 JapUserException (com.fujieid.jap.core.exception.JapUserException)1 JapResponse (com.fujieid.jap.core.result.JapResponse)1 JakartaRequestAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaRequestAdapter)1 JakartaResponseAdapter (com.fujieid.jap.http.adapter.jakarta.JakartaResponseAdapter)1 HttpServletRequestWrapperImpl (com.fujieid.jap.solon.HttpServletRequestWrapperImpl)1 AuthCallback (me.zhyd.oauth.model.AuthCallback)1 AuthRequest (me.zhyd.oauth.request.AuthRequest)1 Get (org.noear.solon.annotation.Get)1 Mapping (org.noear.solon.annotation.Mapping)1