me.zhyd.oauth.request.AuthRequest Java Examples

The following examples show how to use me.zhyd.oauth.request.AuthRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocialLoginServiceImpl.java    From FEBS-Cloud with Apache License 2.0 6 votes vote down vote up
@Override
public FebsResponse resolveLogin(String oauthType, AuthCallback callback) throws FebsException {
    FebsResponse febsResponse = new FebsResponse();
    AuthRequest authRequest = factory.get(getAuthSource(oauthType));
    AuthResponse<?> response = authRequest.login(resolveAuthCallback(callback));
    if (response.ok()) {
        AuthUser authUser = (AuthUser) response.getData();
        UserConnection userConnection = userConnectionService.selectByCondition(authUser.getSource().toString(), authUser.getUuid());
        if (userConnection == null) {
            febsResponse.message(NOT_BIND).data(authUser);
        } else {
            SystemUser user = userManager.findByName(userConnection.getUserName());
            if (user == null) {
                throw new FebsException("系统中未找到与第三方账号对应的账户");
            }
            OAuth2AccessToken oAuth2AccessToken = getOauth2AccessToken(user);
            febsResponse.message(SOCIAL_LOGIN_SUCCESS).data(oAuth2AccessToken);
            febsResponse.put(USERNAME, user.getUsername());
        }
    } else {
        throw new FebsException(String.format("第三方登录失败,%s", response.getMsg()));
    }
    return febsResponse;
}
 
Example #2
Source File: AuthServiceImpl.java    From OneBlog with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean login(String source, AuthCallback callback) {
    AuthRequest authRequest = RequestFactory.getInstance(source).getRequest();
    AuthResponse response = authRequest.login(callback);
    if (response.ok()) {
        AuthUser authUser = (AuthUser) response.getData();
        User newUser = BeanConvertUtil.doConvert(authUser, User.class);
        newUser.setSource(authUser.getSource().toString());
        if (null != authUser.getGender()) {
            newUser.setGender(authUser.getGender().getCode());
        }
        User user = userService.getByUuidAndSource(authUser.getUuid(), authUser.getSource().toString());
        newUser.setUserType(UserTypeEnum.USER);
        if (null != user) {
            newUser.setId(user.getId());
            userService.updateSelective(newUser);
        } else {
            userService.insert(newUser);
        }
        SessionUtil.setUser(newUser);
        return true;
    }
    log.warn("[{}] {}", source, response.getMsg());
    return false;
}
 
Example #3
Source File: BaiduRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getBaidu();
    return new AuthBaiduRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #4
Source File: WechatEnterpriseRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getWechatEnterprise();
    return new AuthWeChatEnterpriseRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .agentId(authConfig.getAgentId())
            .build());
}
 
Example #5
Source File: TeambitionRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getTeambition();
    return new AuthTeambitionRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #6
Source File: StackoverflowRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getStackoverflow();
    return new AuthStackOverflowRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .stackOverflowKey(authConfig.getStackOverflowKey())
            .build());
}
 
Example #7
Source File: HuaweiRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getHuawei();
    return new AuthHuaweiRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #8
Source File: DouyinRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getDouyin();
    return new AuthDouyinRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #9
Source File: AbstractSocialSignOnEndpoint.java    From MaxKey with Apache License 2.0 5 votes vote down vote up
protected AuthRequest buildAuthRequest(String provider){
 		
	SocialSignOnProvider socialSignOnProvider = socialSignOnProviderService.get(provider);
	_logger.debug("socialSignOn Provider : "+socialSignOnProvider);
	
	if(socialSignOnProvider!=null){
		authRequest=socialSignOnProviderService.getAuthRequest(provider);
		WebContext.setAttribute(SOCIALSIGNON_OAUTH_SERVICE_SESSION, authRequest);
		WebContext.setAttribute(SOCIALSIGNON_PROVIDER_SESSION, socialSignOnProvider);
		return authRequest;
	}
	return null;
}
 
Example #10
Source File: LinkedinRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getLinkedin();
    return new AuthLinkedinRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #11
Source File: CodingRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getCoding();
    return new AuthCodingRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #12
Source File: ToutiaoRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getToutiao();
    return new AuthToutiaoRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #13
Source File: TencentCloudRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getTencentCloud();
    return new AuthTencentCloudRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #14
Source File: SocialLoginController.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 登录
 *
 * @param oauthType 第三方登录类型
 * @param response  response
 */
@ResponseBody
@GetMapping("/login/{oauthType}/{type}")
public void renderAuth(@PathVariable String oauthType, @PathVariable String type, HttpServletResponse response) throws IOException, FebsException {
    AuthRequest authRequest = socialLoginService.renderAuth(oauthType);
    response.sendRedirect(authRequest.authorize(oauthType + StringConstant.DOUBLE_COLON + AuthStateUtils.createState()) + "::" + type);
}
 
Example #15
Source File: QqRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getQq();
    return new AuthQqRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #16
Source File: WechatRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getWechat();
    return new AuthWeChatRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #17
Source File: PinterestRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getPinterest();
    return new AuthPinterestRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #18
Source File: GoogleRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getGoogle();
    return new AuthGoogleRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #19
Source File: GithubRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getGithub();
    return new AuthGithubRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #20
Source File: OAuthController.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 收回授权
 *
 * @param source
 * @param token
 * @return
 * @throws IOException
 */
@RequestMapping("/revoke/{source}/{token}")
public ModelAndView revokeAuth(@PathVariable("source") String source, @PathVariable("token") String token) throws IOException {
    AuthRequest authRequest = RequestFactory.getInstance(source).getRequest();
    AuthResponse response = authRequest.revoke(AuthToken.builder().accessToken(token).build());
    if (response.getCode() == 2000) {
        return ResultUtil.redirect("/");
    }
    return ResultUtil.redirect("/login");
}
 
Example #21
Source File: OauthController.java    From cms with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/{type}/callback")
public void login(@PathVariable String type, String redirect, AuthCallback callback, HttpServletResponse response) throws IOException {
    AuthRequest authRequest = factory.get(type);
    AuthResponse authResponse = authRequest.login(callback);
    log.info("【response】= {}", JSONUtil.toJsonStr(authResponse));
    response.sendRedirect(redirect);
}
 
Example #22
Source File: OauthController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 登录成功后的回调
 *
 * @param oauthType 第三方登录类型
 * @param callback  携带返回的信息
 * @return 登录成功后的信息
 */
@RequestMapping("/{oauthType}/callback")
public AuthResponse login(@PathVariable String oauthType, AuthCallback callback) {
    AuthRequest authRequest = factory.get(getAuthSource(oauthType));
    AuthResponse response = authRequest.login(callback);
    log.info("【response】= {}", JSONUtil.toJsonStr(response));
    return response;
}
 
Example #23
Source File: WeiboRequest.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public AuthRequest getRequest() {
    AuthConfig authConfig = properties.getWeibo();
    return new AuthWeiboRequest(AuthConfig.builder()
            .clientId(authConfig.getClientId())
            .clientSecret(authConfig.getClientSecret())
            .redirectUri(authConfig.getRedirectUri())
            .build());
}
 
Example #24
Source File: SocialLoginServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Override
public FebsResponse resolveBind(String oauthType, AuthCallback callback) throws FebsException {
    FebsResponse febsResponse = new FebsResponse();
    AuthRequest authRequest = factory.get(getAuthSource(oauthType));
    AuthResponse<?> response = authRequest.login(resolveAuthCallback(callback));
    if (response.ok()) {
        febsResponse.data(response.getData());
    } else {
        throw new FebsException(String.format("第三方登录失败,%s", response.getMsg()));
    }
    return febsResponse;
}
 
Example #25
Source File: AuthRestApi.java    From mogu_blog_v2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "获取认证", notes = "获取认证")
@RequestMapping("/render")
public String renderAuth(String source, HttpServletResponse response) throws IOException {
    log.info("进入render:" + source);
    AuthRequest authRequest = getAuthRequest(source);
    String token = AuthStateUtils.createState();
    String authorizeUrl = authRequest.authorize(token);
    Map<String, String> map = new HashMap<>();
    map.put(SQLConf.URL, authorizeUrl);
    return ResultUtil.result(SysConf.SUCCESS, map);
}
 
Example #26
Source File: ThirdLoginController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/render/{source}")
public void render(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
    log.info("第三方登录进入render:" + source);
    AuthRequest authRequest = factory.get(source);
    String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
    log.info("第三方登录认证地址:" + authorizeUrl);
    response.sendRedirect(authorizeUrl);
}
 
Example #27
Source File: ThirdLoginController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/render/{source}")
public void render(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
    log.info("第三方登录进入render:" + source);
    AuthRequest authRequest = factory.get(source);
    String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
    log.info("第三方登录认证地址:" + authorizeUrl);
    response.sendRedirect(authorizeUrl);
}
 
Example #28
Source File: OAuth2Realm.java    From Shiro-Action with MIT License 5 votes vote down vote up
private AuthUser extractUserInfo(String code) {
    AuthRequest authRequest = oAuth2Helper.getAuthRequest(getAuthcTypeEnum());
    AuthResponse authResponse = authRequest.login(code);

    // 如果认证失败. 则输出日志, 并将用户重定向到错误页面.
    // 这里出错一般原因为程序的 OAuth2 ClientID 或 clientSecret 或 redirectUrl 配置错误.
    if (authResponse.getCode() == ResponseStatus.FAILURE.getCode()) {
        log.error(authResponse.getMsg());
        WebHelper.redirectUrl("/oauth2/error");
    }

    return (AuthUser) authResponse.getData();
}
 
Example #29
Source File: OAuth2Controller.java    From Shiro-Action with MIT License 5 votes vote down vote up
/**
 * 生成 Github 授权地址
 */
@OperationLog("Github OAuth2 登录")
@GetMapping("/render/github")
@ResponseBody
public ResultBean renderGithubAuth(HttpServletResponse response) {
    AuthRequest authRequest = oAuth2Helper.getAuthRequest(AuthcTypeEnum.GITHUB);
    return ResultBean.successData(authRequest.authorize());
}
 
Example #30
Source File: OAuth2Controller.java    From Shiro-Action with MIT License 5 votes vote down vote up
/**
 * 生成 Gitee 授权地址
 */
@OperationLog("Gitee OAuth2 登录")
@GetMapping("/render/gitee")
@ResponseBody
public ResultBean renderGiteeAuth(HttpServletResponse response) {
    AuthRequest authRequest = oAuth2Helper.getAuthRequest(AuthcTypeEnum.GITEE);
    return ResultBean.successData(authRequest.authorize());
}