🎉 修改认证方式为显式的传参
This commit is contained in:
288
pom.xml
288
pom.xml
@@ -1,111 +1,177 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
<description>史上最全的整合第三方登录的工具, Just Auth</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>yadong.zhang</name>
|
||||
<email>yadong.zhang0415@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven-source.version>2.2.1</maven-source.version>
|
||||
<maven-compiler.version>3.7.0</maven-compiler.version>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<hutool-version>4.1.21</hutool-version>
|
||||
<lombok-version>1.18.4</lombok-version>
|
||||
<junit-version>4.11</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<fastjson-version>1.2.44</fastjson-version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
<version>${hutool-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler.version}</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven-source.version}</version>
|
||||
<inherited>true</inherited>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- GPG -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.zhyd.oauth</groupId>
|
||||
<artifactId>JustAuth</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<name>JustAuth</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
<description>史上最全的整合第三方登录的工具, Just Auth</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth/blob/master/LICENSE</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://gitee.com/yadong.zhang/JustAuth.git</connection>
|
||||
<developerConnection>scm:git:https://gitee.com/yadong.zhang/JustAuth.git</developerConnection>
|
||||
<url>https://gitee.com/yadong.zhang/JustAuth</url>
|
||||
</scm>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>yadong.zhang</name>
|
||||
<email>yadong.zhang0415@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven-source.version>2.2.1</maven-source.version>
|
||||
<maven-compiler.version>3.7.0</maven-compiler.version>
|
||||
<maven.test.skip>true</maven.test.skip>
|
||||
<hutool-version>4.1.21</hutool-version>
|
||||
<lombok-version>1.18.4</lombok-version>
|
||||
<junit-version>4.11</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<fastjson-version>1.2.44</fastjson-version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
<version>${hutool-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler.version}</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven-source.version}</version>
|
||||
<inherited>true</inherited>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- GPG -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>release</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Source -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${maven-source.version}</version>
|
||||
<inherited>true</inherited>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- GPG -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype-oss</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>sonatype-oss</id>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
@@ -7,41 +10,13 @@ package me.zhyd.oauth.config;
|
||||
* @date 2019/1/31 14:03
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class AuthConfig {
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
/**
|
||||
* github应用的Client ID
|
||||
* 登陆成功后的回调地址
|
||||
*/
|
||||
public static String githubClientId = null;
|
||||
/**
|
||||
* github应用的Client Secret
|
||||
*/
|
||||
public static String githubClientSecret = null;
|
||||
/**
|
||||
* github应用的redirect_uri 登陆成功后的回调地址
|
||||
*/
|
||||
public static String githubRedirectUri = null;
|
||||
/**
|
||||
* weibo应用的App Key
|
||||
*/
|
||||
public static String weiboClientId = null;
|
||||
/**
|
||||
* weibo应用的App Secret
|
||||
*/
|
||||
public static String weiboClientSecret = null;
|
||||
/**
|
||||
* weibo应用的redirect_uri 登陆成功后的回调地址
|
||||
*/
|
||||
public static String weiboRedirectUri = null;
|
||||
/**
|
||||
* gitee应用的Client ID
|
||||
*/
|
||||
public static String giteeClientId = null;
|
||||
/**
|
||||
* gitee应用的Client Secret
|
||||
*/
|
||||
public static String giteeClientSecret = null;
|
||||
/**
|
||||
* gitee应用的redirect_uri 登陆成功后的回调地址
|
||||
*/
|
||||
public static String giteeRedirectUri = null;
|
||||
private String redirectUri;
|
||||
}
|
||||
|
||||
16
src/main/java/me/zhyd/oauth/config/GiteeConfig.java
Normal file
16
src/main/java/me/zhyd/oauth/config/GiteeConfig.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/14 13:34
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class GiteeConfig extends AuthConfig {
|
||||
}
|
||||
16
src/main/java/me/zhyd/oauth/config/GithubConfig.java
Normal file
16
src/main/java/me/zhyd/oauth/config/GithubConfig.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/14 13:34
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class GithubConfig extends AuthConfig {
|
||||
}
|
||||
17
src/main/java/me/zhyd/oauth/config/QqConfig.java
Normal file
17
src/main/java/me/zhyd/oauth/config/QqConfig.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/14 13:34
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
@Deprecated
|
||||
public class QqConfig extends AuthConfig {
|
||||
}
|
||||
17
src/main/java/me/zhyd/oauth/config/WechatConfig.java
Normal file
17
src/main/java/me/zhyd/oauth/config/WechatConfig.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/14 13:34
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
@Deprecated
|
||||
public class WechatConfig extends AuthConfig {
|
||||
}
|
||||
16
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
Normal file
16
src/main/java/me/zhyd/oauth/config/WeiboConfig.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package me.zhyd.oauth.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
* @version 1.0
|
||||
* @website https://www.zhyd.me
|
||||
* @date 2019/2/14 13:34
|
||||
* @since 1.8
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class WeiboConfig extends AuthConfig {
|
||||
}
|
||||
@@ -24,11 +24,11 @@ import java.io.IOException;
|
||||
public class AuthGiteeRequest implements AuthRequest {
|
||||
|
||||
@Override
|
||||
public void authorize(HttpServletResponse response) {
|
||||
public void authorize(AuthConfig config, HttpServletResponse response) {
|
||||
if (!AuthConfigChecker.isSupportedGitee()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
String authorizeUrl = UrlBuilder.getGiteeAuthorizeUrl(AuthConfig.giteeClientId, AuthConfig.giteeRedirectUri);
|
||||
String authorizeUrl = UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
try {
|
||||
response.sendRedirect(authorizeUrl);
|
||||
} catch (IOException e) {
|
||||
@@ -37,22 +37,22 @@ public class AuthGiteeRequest implements AuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize() {
|
||||
public String authorize(AuthConfig config) {
|
||||
if (!AuthConfigChecker.isSupportedGitee()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
return UrlBuilder.getGiteeAuthorizeUrl(AuthConfig.giteeClientId, AuthConfig.giteeRedirectUri);
|
||||
return UrlBuilder.getGiteeAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
public AuthResponse login(AuthConfig config, String code) {
|
||||
if (!AuthConfigChecker.isSupportedGitee()) {
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.UNSUPPORTED.getCode())
|
||||
.msg(ResponseStatus.UNSUPPORTED.getMsg())
|
||||
.build();
|
||||
}
|
||||
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(AuthConfig.giteeClientId, AuthConfig.giteeClientSecret, code, AuthConfig.giteeRedirectUri);
|
||||
String accessTokenUrl = UrlBuilder.getGiteeAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
@@ -24,11 +24,11 @@ import java.io.IOException;
|
||||
public class AuthGithubRequest implements AuthRequest {
|
||||
|
||||
@Override
|
||||
public void authorize(HttpServletResponse response) {
|
||||
public void authorize(AuthConfig config, HttpServletResponse response) {
|
||||
if (!AuthConfigChecker.isSupportedGithub()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
String authorizeUrl = UrlBuilder.getGithubAuthorizeUrl(AuthConfig.githubClientId, AuthConfig.githubRedirectUri);
|
||||
String authorizeUrl = UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
try {
|
||||
response.sendRedirect(authorizeUrl);
|
||||
} catch (IOException e) {
|
||||
@@ -37,22 +37,22 @@ public class AuthGithubRequest implements AuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize() {
|
||||
public String authorize(AuthConfig config) {
|
||||
if (!AuthConfigChecker.isSupportedGithub()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
return UrlBuilder.getGithubAuthorizeUrl(AuthConfig.githubClientId, AuthConfig.githubRedirectUri);
|
||||
return UrlBuilder.getGithubAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
public AuthResponse login(AuthConfig config, String code) {
|
||||
if (!AuthConfigChecker.isSupportedGithub()) {
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.UNSUPPORTED.getCode())
|
||||
.msg(ResponseStatus.UNSUPPORTED.getMsg())
|
||||
.build();
|
||||
}
|
||||
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(AuthConfig.githubClientId, AuthConfig.githubClientSecret, code, AuthConfig.githubRedirectUri);
|
||||
String accessTokenUrl = UrlBuilder.getGithubAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
String accessTokenStr = response.body();
|
||||
String accessToken = accessTokenStr.split("&")[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.zhyd.oauth.request;
|
||||
|
||||
import me.zhyd.oauth.config.AuthConfig;
|
||||
import me.zhyd.oauth.exception.AuthException;
|
||||
import me.zhyd.oauth.model.AuthResponse;
|
||||
|
||||
@@ -17,26 +18,30 @@ public interface AuthRequest {
|
||||
/**
|
||||
* 自动跳转到认证页面
|
||||
*
|
||||
* @param config 授权的配置,对应不同平台
|
||||
* @param response response
|
||||
*/
|
||||
default void authorize(HttpServletResponse response) {
|
||||
default void authorize(AuthConfig config, HttpServletResponse response) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回认证url,可自行跳转页面
|
||||
*
|
||||
* @param config 授权的配置,对应不同平台
|
||||
*/
|
||||
default String authorize() {
|
||||
default String authorize(AuthConfig config) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方登录
|
||||
*
|
||||
* @param code 通过authorize换回的code
|
||||
* @param config 授权的配置,对应不同平台
|
||||
* @param code 通过authorize换回的code
|
||||
* @return 返回登陆成功后的用户信息
|
||||
*/
|
||||
default AuthResponse login(String code) {
|
||||
default AuthResponse login(AuthConfig config, String code) {
|
||||
throw new AuthException(ResponseStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import me.zhyd.oauth.utils.UrlBuilder;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||
@@ -28,11 +27,11 @@ import java.net.InetAddress;
|
||||
public class AuthWeiboRequest implements AuthRequest {
|
||||
|
||||
@Override
|
||||
public void authorize(HttpServletResponse response) {
|
||||
public void authorize(AuthConfig config, HttpServletResponse response) {
|
||||
if (!AuthConfigChecker.isSupportedWeibo()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
String authorizeUrl = UrlBuilder.getWeiboAuthorizeUrl(AuthConfig.weiboClientId, AuthConfig.weiboRedirectUri);
|
||||
String authorizeUrl = UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
try {
|
||||
response.sendRedirect(authorizeUrl);
|
||||
} catch (IOException e) {
|
||||
@@ -41,22 +40,22 @@ public class AuthWeiboRequest implements AuthRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String authorize() {
|
||||
public String authorize(AuthConfig config) {
|
||||
if (!AuthConfigChecker.isSupportedWeibo()) {
|
||||
throw new AuthException(ResponseStatus.UNSUPPORTED);
|
||||
}
|
||||
return UrlBuilder.getWeiboAuthorizeUrl(AuthConfig.weiboClientId, AuthConfig.weiboRedirectUri);
|
||||
return UrlBuilder.getWeiboAuthorizeUrl(config.getClientId(), config.getRedirectUri());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthResponse login(String code) {
|
||||
public AuthResponse login(AuthConfig config, String code) {
|
||||
if (!AuthConfigChecker.isSupportedWeibo()) {
|
||||
return AuthResponse.builder()
|
||||
.code(ResponseStatus.UNSUPPORTED.getCode())
|
||||
.msg(ResponseStatus.UNSUPPORTED.getMsg())
|
||||
.build();
|
||||
}
|
||||
String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(AuthConfig.weiboClientId, AuthConfig.weiboClientSecret, code, AuthConfig.weiboRedirectUri);
|
||||
String accessTokenUrl = UrlBuilder.getWeiboAccessTokenUrl(config.getClientId(), config.getClientSecret(), code, config.getRedirectUri());
|
||||
HttpResponse response = HttpRequest.post(accessTokenUrl).execute();
|
||||
String accessTokenStr = response.body();
|
||||
JSONObject accessTokenObject = JSONObject.parseObject(accessTokenStr);
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.net.UnknownHostException;
|
||||
* @date 2019/1/31 16:31
|
||||
* @since 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class IpUtils {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user