Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sso
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sso
Commits
a3880ef8
Commit
a3880ef8
authored
Aug 07, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
329817e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
48 deletions
+56
-48
OAuthApi.java
src/main/java/com/egolm/sso/oauth/OAuthApi.java
+56
-48
No files found.
src/main/java/com/egolm/sso/oauth/OAuthApi.java
View file @
a3880ef8
...
@@ -33,51 +33,52 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -33,51 +33,52 @@ import com.alibaba.fastjson.JSONObject;
* <p>以下为接口实现案例</p>
* <p>以下为接口实现案例</p>
* <p>Example():</p>
* <p>Example():</p>
* <pre>
* <pre>
public class OAuthApiImpl implements OAuthApi {
* <span>@</span>Component
* public class OAuthApiImpl implements OAuthApi {
private OAuthConfig config;
*
* private OAuthConfig config;
<span>@</span>Autowired
*
HttpServletRequest request;
* <span>@</span>Autowired
* HttpServletRequest request;
<span>@</span>Autowired
*
HttpServletResponse response;
* <span>@</span>Autowired
* HttpServletResponse response;
*
<span>@</span>Value("${client_id}") private String clientId;
*
<span>@</span>Value("${client_secret}") private String clientSecret;
* <span>@</span>Value("${client_id}") private String clientId;
<span>@</span>Value("${callback_url}") private String callbackUrl;
* <span>@</span>Value("${client_secret}") private String clientSecret;
<span>@</span>Value("${authorize_url}") private String authorizeUrl;
* <span>@</span>Value("${callback_url}") private String callbackUrl;
<span>@</span>Value("${access_token_url}") private String accessTokenUrl;
* <span>@</span>Value("${authorize_url}") private String authorizeUrl;
* <span>@</span>Value("${access_token_url}") private String accessTokenUrl;
<span>@</span>Override
*
public OAuthConfig getOAuthConfig() {
* <span>@</span>Override
if(config == null) {
* public OAuthConfig getOAuthConfig() {
synchronized (this) {
* if(config == null) {
if(config == null) {
* synchronized (this) {
config = new OAuthConfig();
* if(config == null) {
config.setAccessTokenUrl(accessTokenUrl);
* config = new OAuthConfig();
config.setAuthorizeUrl(authorizeUrl);
* config.setAccessTokenUrl(accessTokenUrl);
config.setCallbackUrl(callbackUrl);
* config.setAuthorizeUrl(authorizeUrl);
config.setClientId(clientId);
* config.setCallbackUrl(callbackUrl);
config.setClientSecret(clientSecret);
* config.setClientId(clientId);
}
* config.setClientSecret(clientSecret);
}
* }
}
* }
return config;
* }
}
* return config;
* }
<span>@</span>Override
*
public HttpServletRequest getHttpServletRequest() {
* <span>@</span>Override
return request;
* public HttpServletRequest getHttpServletRequest() {
}
* return request;
* }
<span>@</span>Override
*
public HttpServletResponse getHttpServletResponse() {
* <span>@</span>Override
return response;
* public HttpServletResponse getHttpServletResponse() {
}
* return response;
* }
}
*
* }
* </pre>
* </pre>
*
*
*
*
...
@@ -86,25 +87,31 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -86,25 +87,31 @@ import com.alibaba.fastjson.JSONObject;
* <p>以下为接口调用案例</p>
* <p>以下为接口调用案例</p>
* <p>Example():</p>
* <p>Example():</p>
* <pre>
* <pre>
* <span>@</span>Controller
* <span>@</span>RequestMapping
* public class LoginController {
* public class LoginController {
*
*
* <span>@</span>Autowired
* OAuthApi oAuthApi;
* OAuthApi oAuthApi;
*
*
* <span>@</span>GetMapping
* public ModelAndView index() {
* public ModelAndView index() {
* OAuthConfig config = oAuthApi.getOAuthConfig();
* OAuthConfig config = oAuthApi.getOAuthConfig();
* ModelAndView mav = new ModelAndView();
* ModelAndView mav = new ModelAndView();
* mav.addObject("loginUrl", oAuthApi.getAuthorizationUrl());
//设置登陆授权URL, 用户可以在页面点击此URL,进入OAuth系统授权
* mav.addObject("loginUrl", oAuthApi.getAuthorizationUrl());
* mav.addObject("config", config);
* mav.addObject("config", config);
* mav.setViewName("index.html");
* mav.setViewName("index.html");
* return mav;
* return mav;
* }
* }
*
*
* <span>@</span>GetMapping("toLogin")
* public void toLogin() {
* public void toLogin() {
* oAuthApi.doRedirectOAuthLogin();
//直接转到OAuth系统授权,和用户主动在页面点击授权URL效果一样,都是跳转到一样的地址
* oAuthApi.doRedirectOAuthLogin();
* }
* }
*
*
* <span>@</span>RequestMapping(value="callback", method= {RequestMethod.GET, RequestMethod.POST})
* public ModelAndView doLogin() {
* public ModelAndView doLogin() {
* oAuthApi.callback();
//授权成功后,授权系统通过重定向的方式回调业务系统,并附带授权参数信息,此代码用于解析授权系统的回调参数
* oAuthApi.callback();
* OAuthToken token = oAuthApi.getOAuthToken();
* OAuthToken token = oAuthApi.getOAuthToken();
* ModelAndView mav = new ModelAndView();
* ModelAndView mav = new ModelAndView();
* mav.addObject("token", token);
* mav.addObject("token", token);
...
@@ -112,6 +119,7 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -112,6 +119,7 @@ import com.alibaba.fastjson.JSONObject;
* return mav;
* return mav;
* }
* }
*
*
* <span>@</span>RequestMapping(value="doLogout", method= {RequestMethod.GET, RequestMethod.POST})
* public ModelAndView doLogout(HttpServletResponse response) throws IOException {
* public ModelAndView doLogout(HttpServletResponse response) throws IOException {
* oAuthApi.removeOAuthToken();
* oAuthApi.removeOAuthToken();
* ModelAndView mav = new ModelAndView();
* ModelAndView mav = new ModelAndView();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment