Skip to content

Commit

Permalink
⬆️ 升级 JustAuth 版本为 1.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
xkcoding committed Aug 1, 2019
1 parent 5af6745 commit f921f55
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 47 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 版本更新记录

### 【0.0.2】2019-08-01

- 升级 `JustAuth` 版本:1.9.5

### 【0.0.1】2019-07-23

- 使用 `JustAuth` 版本:1.9.2

37 changes: 6 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ https://github.com/xkcoding/justauth-spring-boot-starter-demo
<dependency>
<groupId>com.xkcoding</groupId>
<artifactId>justauth-spring-boot-starter</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>
```

Expand All @@ -41,31 +41,7 @@ justauth:
- 然后就开始玩耍吧~
```java
package com.xkcoding.justauthspringbootstarterdemo;

import com.xkcoding.justauth.AuthRequestFactory;
import lombok.RequiredArgsConstructor;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* <p>
* 测试 Controller
* </p>
*
* @author yangkai.shen
* @date Created in 2019-07-22 11:17
*/
@Slf4j
@RestController
@RequestMapping("/oauth")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
Expand All @@ -75,15 +51,14 @@ public class TestController {
@GetMapping("/login/qq")
public void login(HttpServletResponse response) throws IOException {
AuthRequest authRequest = factory.get(AuthSource.QQ);
response.sendRedirect(authRequest.authorize());
response.sendRedirect(authRequest.authorize(AuthStateUtils.createState()));
}

@RequestMapping("/qq/callback")
public AuthResponse login(AuthCallback callback) {
AuthRequest authRequest = factory.get(AuthSource.QQ);
AuthResponse response = authRequest.login(callback);
// 移除校验通过的state
AuthState.delete(AuthSource.QQ);
AuthRequest authRequest2 = factory.get(AuthSource.QQ);
AuthResponse response = authRequest2.login(callback);
log.info("【response】= {}", JSONUtil.toJsonStr(response));
return response;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xkcoding</groupId>
<artifactId>justauth-spring-boot-starter</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.2</version>

<name>justauth-spring-boot-starter</name>
<url>https://github.com/xkcoding/justauth-spring-boot-starter</url>
Expand Down Expand Up @@ -50,7 +50,7 @@
<!--SpringBoot版本-->
<spring-boot.version>2.1.6.RELEASE</spring-boot.version>
<!--JustAuth版本-->
<justauth.version>1.9.3-SNAPSHOT</justauth.version>
<justauth.version>1.9.5</justauth.version>
</properties>

<dependencies>
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/com/xkcoding/justauth/AuthRequestFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import lombok.RequiredArgsConstructor;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.request.*;
import me.zhyd.oauth.utils.AuthState;

/**
* <p>
Expand All @@ -26,19 +27,7 @@ public class AuthRequestFactory {
* @return {@link AuthRequest}
*/
public AuthRequest get(AuthSource source) {
return get(source, null);
}

/**
* 返回AuthRequest对象
*
* @param source {@link AuthSource}
* @param state {@link AuthSource}
* @return {@link AuthRequest}
*/
public AuthRequest get(AuthSource source, Object state) {
AuthConfig config = properties.getType().get(source);
config.setState(state == null ? AuthState.create(source) : AuthState.create(source, state));
switch (source) {
case GITHUB:
return new AuthGithubRequest(config);
Expand Down Expand Up @@ -89,7 +78,7 @@ public AuthRequest get(AuthSource source, Object state) {
case STACK_OVERFLOW:
return new AuthStackOverflowRequest(config);
default:
return null;
throw new AuthException(AuthResponseStatus.UNSUPPORTED);
}
}
}

0 comments on commit f921f55

Please sign in to comment.