Skip to content

Commit

Permalink
👽 AuthConfig 中 CodingGroupName 改为 DomainPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyd-c committed Mar 30, 2021
1 parent bc3af96 commit 3753e3b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
36 changes: 31 additions & 5 deletions src/main/java/me/zhyd/oauth/config/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.xkcoding.http.config.HttpConfig;
import lombok.*;
import me.zhyd.oauth.enums.scope.AuthScope;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.utils.StringUtils;

import java.util.List;

Expand Down Expand Up @@ -66,13 +66,17 @@ public class AuthConfig {
private String agentId;

/**
* 使用 Coding 登录时,需要传该值
* 域名前缀
* <p>
* 团队域名前缀,比如以“ https://justauth.coding.net/ ”为例,{@code codingGroupName} = justauth
* 使用 Coding 登录和 Okta 登录时,需要传该值。
* <p>
* Coding 登录:团队域名前缀,比如以“ https://justauth.coding.net ”为例,{@code domainPrefix} = justauth
* <p>
* Okta 登录:Okta 账号域名前缀,比如以“ https://justauth.okta.com ”为例,{@code domainPrefix} = justauth
*
* @since 1.15.5
* @since 1.16.0
*/
private String codingGroupName;
private String domainPrefix;

/**
* 针对国外服务可以单独设置代理
Expand Down Expand Up @@ -138,4 +142,26 @@ public class AuthConfig {
* @since 1.15.9
*/
private boolean pkce;

/**
* Okta 授权服务器的 ID, 默认为 default。如果要使用自定义授权服务,此处传实际的授权服务器 ID(一个随机串)
* <p>
* 创建自定义授权服务器,请参考:
* <p>
* ① https://developer.okta.com/docs/concepts/auth-servers
* <p>
* ② https://developer.okta.com/docs/guides/customize-authz-server
*
* @since 1.16.0
*/
private String authServerId;

/**
* 适配 builder 模式 set 值的情况
*
* @return authServerId
*/
public String getAuthServerId() {
return StringUtils.isEmpty(authServerId) ? "default" : authServerId;
}
}
6 changes: 3 additions & 3 deletions src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void checkResponse(JSONObject object) {
*/
@Override
public String authorize(String state) {
return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getCodingGroupName()))
return UrlBuilder.fromBaseUrl(String.format(source.authorize(), config.getDomainPrefix()))
.queryParam("response_type", "code")
.queryParam("client_id", config.getClientId())
.queryParam("redirect_uri", config.getRedirectUri())
Expand All @@ -102,7 +102,7 @@ public String authorize(String state) {
*/
@Override
public String accessTokenUrl(String code) {
return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getCodingGroupName()))
return UrlBuilder.fromBaseUrl(String.format(source.accessToken(), config.getDomainPrefix()))
.queryParam("code", code)
.queryParam("client_id", config.getClientId())
.queryParam("client_secret", config.getClientSecret())
Expand All @@ -119,7 +119,7 @@ public String accessTokenUrl(String code) {
*/
@Override
public String userInfoUrl(AuthToken authToken) {
return UrlBuilder.fromBaseUrl(String.format(source.userInfo(), config.getCodingGroupName()))
return UrlBuilder.fromBaseUrl(String.format(source.userInfo(), config.getDomainPrefix()))
.queryParam("access_token", authToken.getAccessToken())
.build();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/zhyd/oauth/utils/AuthChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static boolean isSupportedAuth(AuthConfig config, AuthSource source) {
if (isSupported && AuthDefaultSource.WECHAT_ENTERPRISE == source) {
isSupported = StringUtils.isNotEmpty(config.getAgentId());
}
if (isSupported && AuthDefaultSource.CODING == source) {
isSupported = StringUtils.isNotEmpty(config.getCodingGroupName());
if (isSupported && (AuthDefaultSource.CODING == source || AuthDefaultSource.OKTA == source)) {
isSupported = StringUtils.isNotEmpty(config.getDomainPrefix());
}
if (isSupported && AuthDefaultSource.XMLY == source) {
isSupported = StringUtils.isNotEmpty(config.getDeviceId()) && null != config.getClientOsType();
Expand Down

0 comments on commit 3753e3b

Please sign in to comment.