mirror of
https://gitee.com/yadong.zhang/JustAuth.git
synced 2026-01-07 19:31:48 +08:00
48 lines
1.7 KiB
Java
48 lines
1.7 KiB
Java
package me.zhyd.oauth.url;
|
|
|
|
import me.zhyd.oauth.config.AuthSource;
|
|
import me.zhyd.oauth.exception.AuthException;
|
|
import me.zhyd.oauth.model.AuthResponseStatus;
|
|
import me.zhyd.oauth.url.entity.AuthUserInfoEntity;
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
/**
|
|
* Github相关的URL构建类
|
|
*
|
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
|
* @version 1.0
|
|
* @since 1.8
|
|
*/
|
|
public class AuthGithubUrlBuilder extends AuthDefaultUrlBuilder {
|
|
|
|
private static final String GITHUB_ACCESS_TOKEN_PATTERN = "{0}?client_id={1}&client_secret={2}&code={3}&redirect_uri={4}";
|
|
private static final String GITHUB_USER_INFO_PATTERN = "{0}?access_token={1}";
|
|
private static final String GITHUB_AUTHORIZE_PATTERN = "{0}?client_id={1}&redirect_uri={2}&state={3}";
|
|
|
|
@Override
|
|
public String getAccessTokenUrl(String code) {
|
|
return MessageFormat.format(GITHUB_ACCESS_TOKEN_PATTERN, AuthSource.GITHUB.accessToken(), config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
|
}
|
|
|
|
@Override
|
|
public String getUserInfoUrl(AuthUserInfoEntity userInfoEntity) {
|
|
return MessageFormat.format(GITHUB_USER_INFO_PATTERN, AuthSource.GITHUB.userInfo(), userInfoEntity.getAccessToken());
|
|
}
|
|
|
|
@Override
|
|
public String getAuthorizeUrl() {
|
|
return MessageFormat.format(GITHUB_AUTHORIZE_PATTERN, AuthSource.GITHUB.authorize(), config.getClientId(), config.getRedirectUri(), this.getRealState(config.getState()));
|
|
}
|
|
|
|
@Override
|
|
public String getRefreshUrl(String refreshToken) {
|
|
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
|
|
}
|
|
|
|
@Override
|
|
public String getRevokeUrl(String accessToken) {
|
|
throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED);
|
|
}
|
|
}
|