Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
solo-1
Commits
783fd06f
Unverified
Commit
783fd06f
authored
Feb 15, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
:octocat: 动态获取应用客户端 id
parent
0640f72a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
7 deletions
+24
-7
src/main/java/org/b3log/solo/processor/OAuthGitHubProcessor.java
...n/java/org/b3log/solo/processor/OAuthGitHubProcessor.java
+24
-7
No files found.
src/main/java/org/b3log/solo/processor/OAuthGitHubProcessor.java
View file @
783fd06f
...
@@ -17,8 +17,11 @@
...
@@ -17,8 +17,11 @@
*/
*/
package
org
.
b3log
.
solo
.
processor
;
package
org
.
b3log
.
solo
.
processor
;
import
jodd.http.HttpRequest
;
import
jodd.http.HttpResponse
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.ioc.Inject
;
import
org.b3log.latke.ioc.Inject
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Level
;
...
@@ -31,6 +34,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing;
...
@@ -31,6 +34,7 @@ import org.b3log.latke.servlet.annotation.RequestProcessing;
import
org.b3log.latke.servlet.annotation.RequestProcessor
;
import
org.b3log.latke.servlet.annotation.RequestProcessor
;
import
org.b3log.latke.util.Requests
;
import
org.b3log.latke.util.Requests
;
import
org.b3log.latke.util.URLs
;
import
org.b3log.latke.util.URLs
;
import
org.b3log.solo.model.Common
;
import
org.b3log.solo.model.Option
;
import
org.b3log.solo.model.Option
;
import
org.b3log.solo.model.UserExt
;
import
org.b3log.solo.model.UserExt
;
import
org.b3log.solo.service.*
;
import
org.b3log.solo.service.*
;
...
@@ -51,7 +55,7 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -51,7 +55,7 @@ import java.util.concurrent.ConcurrentHashMap;
* </ul>
* </ul>
*
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.
3, Jan 29
, 2019
* @version 1.0.0.
4, Feb 15
, 2019
* @since 2.9.5
* @since 2.9.5
*/
*/
@RequestProcessor
@RequestProcessor
...
@@ -62,11 +66,6 @@ public class OAuthGitHubProcessor {
...
@@ -62,11 +66,6 @@ public class OAuthGitHubProcessor {
*/
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
OAuthGitHubProcessor
.
class
);
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
OAuthGitHubProcessor
.
class
);
/**
* Client id.
*/
private
static
final
String
CLIENT_ID
=
"77f93670fee557f1a613"
;
/**
/**
* OAuth parameters - state.
* OAuth parameters - state.
*/
*/
...
@@ -121,6 +120,24 @@ public class OAuthGitHubProcessor {
...
@@ -121,6 +120,24 @@ public class OAuthGitHubProcessor {
*/
*/
@RequestProcessing
(
value
=
"/oauth/github/redirect"
,
method
=
HttpMethod
.
GET
)
@RequestProcessing
(
value
=
"/oauth/github/redirect"
,
method
=
HttpMethod
.
GET
)
public
void
redirectGitHub
(
final
RequestContext
context
)
{
public
void
redirectGitHub
(
final
RequestContext
context
)
{
final
HttpResponse
res
=
HttpRequest
.
get
(
"https://hacpai.com/oauth/solo/client"
).
trustAllCerts
(
true
).
connectionTimeout
(
3000
).
timeout
(
7000
).
header
(
"User-Agent"
,
Solos
.
USER_AGENT
).
send
();
if
(
HttpServletResponse
.
SC_OK
!=
res
.
statusCode
())
{
LOGGER
.
log
(
Level
.
ERROR
,
"Gets oauth client id failed: "
+
res
.
toString
());
context
.
sendError
(
HttpServletResponse
.
SC_NOT_FOUND
);
return
;
}
res
.
charset
(
"UTF-8"
);
final
JSONObject
result
=
new
JSONObject
(
res
.
bodyText
());
if
(
0
!=
result
.
optInt
(
Keys
.
CODE
))
{
LOGGER
.
log
(
Level
.
ERROR
,
"Gets oauth client id failed: "
+
result
.
optString
(
Keys
.
MSG
));
return
;
}
final
String
clientId
=
result
.
optString
(
Common
.
DATA
);
String
referer
=
context
.
param
(
"referer"
);
String
referer
=
context
.
param
(
"referer"
);
if
(
StringUtils
.
isBlank
(
referer
))
{
if
(
StringUtils
.
isBlank
(
referer
))
{
referer
=
Latkes
.
getServePath
();
referer
=
Latkes
.
getServePath
();
...
@@ -128,7 +145,7 @@ public class OAuthGitHubProcessor {
...
@@ -128,7 +145,7 @@ public class OAuthGitHubProcessor {
final
String
state
=
referer
+
":::"
+
RandomStringUtils
.
randomAlphanumeric
(
16
);
final
String
state
=
referer
+
":::"
+
RandomStringUtils
.
randomAlphanumeric
(
16
);
STATES
.
put
(
state
,
URLs
.
encode
(
state
));
STATES
.
put
(
state
,
URLs
.
encode
(
state
));
final
String
path
=
"https://github.com/login/oauth/authorize"
+
"?client_id="
+
CLIENT_ID
+
"&state="
+
state
final
String
path
=
"https://github.com/login/oauth/authorize"
+
"?client_id="
+
clientId
+
"&state="
+
state
+
"&scope=public_repo,user"
;
+
"&scope=public_repo,user"
;
context
.
sendRedirect
(
path
);
context
.
sendRedirect
(
path
);
...
...
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