me.zhyd.oauth.config.AuthSource Java Examples

The following examples show how to use me.zhyd.oauth.config.AuthSource. 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: AuthChecker.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * 是否支持第三方登录
 *
 * @param config config
 * @param source source
 * @return true or false
 * @since 1.6.1-beta
 */
public static boolean isSupportedAuth(AuthConfig config, AuthSource source) {
    boolean isSupported = StringUtils.isNotEmpty(config.getClientId()) && StringUtils.isNotEmpty(config.getClientSecret()) && StringUtils.isNotEmpty(config.getRedirectUri());
    if (isSupported && AuthDefaultSource.ALIPAY == source) {
        isSupported = StringUtils.isNotEmpty(config.getAlipayPublicKey());
    }
    if (isSupported && AuthDefaultSource.STACK_OVERFLOW == source) {
        isSupported = StringUtils.isNotEmpty(config.getStackOverflowKey());
    }
    if (isSupported && AuthDefaultSource.WECHAT_ENTERPRISE == source) {
        isSupported = StringUtils.isNotEmpty(config.getAgentId());
    }
    if (isSupported && AuthDefaultSource.CODING == source) {
        isSupported = StringUtils.isNotEmpty(config.getCodingGroupName());
    }
    return isSupported;
}
 
Example #2
Source File: AuthChecker.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * 检查配置合法性。针对部分平台, 对redirect uri有特定要求。一般来说redirect uri都是http://,而对于facebook平台, redirect uri 必须是https的链接
 *
 * @param config config
 * @param source source
 * @since 1.6.1-beta
 */
public static void checkConfig(AuthConfig config, AuthSource source) {
    String redirectUri = config.getRedirectUri();
    if (!GlobalAuthUtils.isHttpProtocol(redirectUri) && !GlobalAuthUtils.isHttpsProtocol(redirectUri)) {
        throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI, source);
    }
    // facebook的回调地址必须为https的链接
    if (AuthDefaultSource.FACEBOOK == source && !GlobalAuthUtils.isHttpsProtocol(redirectUri)) {
        // Facebook's redirect uri must use the HTTPS protocol
        throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI, source);
    }
    // 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1
    if (AuthDefaultSource.ALIPAY == source && GlobalAuthUtils.isLocalHost(redirectUri)) {
        // The redirect uri of alipay is forbidden to use localhost or 127.0.0.1
        throw new AuthException(AuthResponseStatus.ILLEGAL_REDIRECT_URI, source);
    }
}
 
Example #3
Source File: AuthChecker.java    From JustAuth with MIT License 6 votes vote down vote up
/**
 * 校验回调传回的code
 * <p>
 * {@code v1.10.0}版本中改为传入{@code source}和{@code callback},对于不同平台使用不同参数接受code的情况统一做处理
 *
 * @param source   当前授权平台
 * @param callback 从第三方授权回调回来时传入的参数集合
 * @since 1.8.0
 */
public static void checkCode(AuthSource source, AuthCallback callback) {
    // 推特平台不支持回调 code 和 state
    if (source == AuthDefaultSource.TWITTER) {
        return;
    }
    String code = callback.getCode();
    if (source == AuthDefaultSource.ALIPAY) {
        code = callback.getAuth_code();
    } else if (source == AuthDefaultSource.HUAWEI) {
        code = callback.getAuthorization_code();
    }
    if (StringUtils.isEmpty(code)) {
        throw new AuthException(AuthResponseStatus.ILLEGAL_CODE, source);
    }
}
 
Example #4
Source File: SocialLoginServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
private AuthSource getAuthSource(String type) throws FebsException {
    if (StrUtil.isNotBlank(type)) {
        return AuthSource.valueOf(type.toUpperCase());
    } else {
        throw new FebsException(String.format("暂不支持%s第三方登录", type));
    }
}
 
Example #5
Source File: AuthDefaultRequest.java    From JustAuth with MIT License 5 votes vote down vote up
public AuthDefaultRequest(AuthConfig config, AuthSource source, AuthStateCache authStateCache) {
    this.config = config;
    this.source = source;
    this.authStateCache = authStateCache;
    if (!AuthChecker.isSupportedAuth(config, source)) {
        throw new AuthException(AuthResponseStatus.PARAMETER_INCOMPLETE, source);
    }
    // 校验配置合法性
    AuthChecker.checkConfig(config, source);
}
 
Example #6
Source File: CustomTags.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取所有可用的Oauth平台
 *
 * @param params
 * @return
 */
public Object listAvailableOAuthPlatforms(Map params) {
    List<String> list = new ArrayList<>();
    try {
        for (Field f : authProperties.getClass().getDeclaredFields()) {
            f.setAccessible(true);
            String fieldName = f.getName();
            AuthSource source = null;
            if ("tencentCloud".equals(fieldName)) {
                source = AuthSource.TENCENT_CLOUD;
            } else if ("stackoverflow".equals(fieldName)) {
                source = AuthSource.STACK_OVERFLOW;
            } else if ("wechatEnterprise".equals(fieldName)) {
                source = AuthSource.WECHAT_ENTERPRISE;
            } else {
                source = AuthSource.valueOf(fieldName.toUpperCase());
            }
            AuthConfig authConfig = (AuthConfig) f.get(authProperties);
            if (null != authConfig) {
                if (AuthChecker.isSupportedAuth(authConfig, source)) {
                    list.add(fieldName);
                }
            }

        }
    } catch (Exception e) {
        log.error("获取所有可用的Oauth平台发生异常", e);
    }

    return list;
}
 
Example #7
Source File: OauthController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
private AuthSource getAuthSource(String type) {
    if (StrUtil.isNotBlank(type)) {
        return AuthSource.valueOf(type.toUpperCase());
    } else {
        throw new RuntimeException("不支持的类型");
    }
}
 
Example #8
Source File: AuthDefaultRequest.java    From JustAuth with MIT License 4 votes vote down vote up
public AuthDefaultRequest(AuthConfig config, AuthSource source) {
    this(config, source, AuthDefaultStateCache.INSTANCE);
}
 
Example #9
Source File: AuthException.java    From JustAuth with MIT License 4 votes vote down vote up
public AuthException(String errorMsg, AuthSource source) {
    this(AuthResponseStatus.FAILURE.getCode(), errorMsg, source);
}
 
Example #10
Source File: AuthException.java    From JustAuth with MIT License 4 votes vote down vote up
public AuthException(int errorCode, String errorMsg, AuthSource source) {
    this(errorCode, String.format("%s [%s]", errorMsg, source.getName()));
}
 
Example #11
Source File: AuthException.java    From JustAuth with MIT License 4 votes vote down vote up
public AuthException(AuthResponseStatus status, AuthSource source) {
    this(status.getCode(), status.getMsg(), source);
}
 
Example #12
Source File: AuthChecker.java    From JustAuth with MIT License 3 votes vote down vote up
/**
 * 校验回调传回的{@code state},为空或者不存在
 * <p>
 * {@code state}不存在的情况只有两种:
 * 1. {@code state}已使用,被正常清除
 * 2. {@code state}为前端伪造,本身就不存在
 *
 * @param state          {@code state}一定不为空
 * @param source         {@code source}当前授权平台
 * @param authStateCache {@code authStateCache} state缓存实现
 */
public static void checkState(String state, AuthSource source, AuthStateCache authStateCache) {
    // 推特平台不支持回调 code 和 state
    if (source == AuthDefaultSource.TWITTER) {
        return;
    }
    if (StringUtils.isEmpty(state) || !authStateCache.containsKey(state)) {
        throw new AuthException(AuthResponseStatus.ILLEGAL_STATUS, source);
    }
}