Java Code Examples for me.zhyd.oauth.model.AuthResponse#ok()

The following examples show how to use me.zhyd.oauth.model.AuthResponse#ok() . 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: 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;
}