Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
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
poc
poc-api
Commits
62d83597
Commit
62d83597
authored
Dec 27, 2024
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改谷歌登录配置
parent
603379ec
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
9 deletions
+48
-9
pom.xml
pom.xml
+7
-1
GoogleLoginChannel.java
...main/java/cn/com/poc/user/builder/GoogleLoginChannel.java
+8
-4
config-dev.properties
src/main/resources/framemax-config/config-dev.properties
+1
-1
config-prod.properties
src/main/resources/framemax-config/config-prod.properties
+1
-1
config-sit.properties
src/main/resources/framemax-config/config-sit.properties
+1
-1
config-uat.properties
src/main/resources/framemax-config/config-uat.properties
+1
-1
LoginChannelTest.java
src/test/java/cn/com/poc/user/builder/LoginChannelTest.java
+29
-0
No files found.
pom.xml
View file @
62d83597
...
...
@@ -14,6 +14,12 @@
</properties>
<dependencyManagement>
<dependencies>
<!-- 指定 httpclient 的版本 -->
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5.9
</version>
</dependency>
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
...
...
@@ -153,7 +159,7 @@
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.5
</version>
<version>
4.5
.9
</version>
</dependency>
...
...
src/main/java/cn/com/poc/user/builder/GoogleLoginChannel.java
View file @
62d83597
...
...
@@ -14,6 +14,7 @@ import cn.com.yict.framemax.frame.service.FmxParamConfigService;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken.Payload
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
;
import
com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager
;
import
com.google.api.client.http.HttpTransport
;
import
com.google.api.client.http.apache.v2.ApacheHttpTransport
;
import
com.google.api.client.json.JsonFactory
;
...
...
@@ -36,6 +37,10 @@ public class GoogleLoginChannel implements LoginChannelService {
private
static
final
String
CLIENT_ID
=
Config
.
get
(
"google.client.id"
);
private
final
HttpTransport
transport
=
new
ApacheHttpTransport
();
private
final
JsonFactory
jsonFactory
=
new
GsonFactory
();
@Resource
private
BizMemberInfoService
bizMemberInfoService
;
...
...
@@ -45,12 +50,11 @@ public class GoogleLoginChannel implements LoginChannelService {
@Resource
private
FmxParamConfigService
fmxParamConfigService
;
@Override
public
BaseModel
doLogin
(
MemberLoginRequestDto
memberLoginRequest
)
throws
Exception
{
HttpTransport
transport
=
new
ApacheHttpTransport
(
);
JsonFactory
jsonFactory
=
new
GsonFactory
(
);
GoogleIdTokenVerifier
verifier
=
new
GoogleIdTokenVerifier
.
Builder
(
transport
,
jsonFactory
)
GooglePublicKeysManager
.
Builder
builder
=
new
GooglePublicKeysManager
.
Builder
(
transport
,
jsonFactory
);
builder
.
setPublicCertsEncodedUrl
(
"https://google-api.gsstcloud.com/oauth2/v1/certs"
);
GoogleIdTokenVerifier
verifier
=
new
GoogleIdTokenVerifier
.
Builder
(
builder
.
build
()
)
.
setAudience
(
Collections
.
singletonList
(
CLIENT_ID
))
.
build
();
...
...
src/main/resources/framemax-config/config-dev.properties
View file @
62d83597
...
...
@@ -26,4 +26,4 @@ large-model.apikey=sk-bNzgFwFtw3k4jR7CE3575a19C3304a53Bb803cCeDeC154F2
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://poc-sit.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
698774957461-b3s1l98m7qjv5ilphvlo57gjhbs7fnfm.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
src/main/resources/framemax-config/config-prod.properties
View file @
62d83597
...
...
@@ -26,4 +26,4 @@ large-model.apikey=sk-gQM7bpiRxaOl2emt0cBbF47481C5403885263eFeB95c7a8e
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://model-link.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
698774957461-b3s1l98m7qjv5ilphvlo57gjhbs7fnfm.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
src/main/resources/framemax-config/config-sit.properties
View file @
62d83597
...
...
@@ -26,4 +26,4 @@ large-model.apikey=sk-bNzgFwFtw3k4jR7CE3575a19C3304a53Bb803cCeDeC154F2
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://poc-sit.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
698774957461-b3s1l98m7qjv5ilphvlo57gjhbs7fnfm.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
src/main/resources/framemax-config/config-uat.properties
View file @
62d83597
...
...
@@ -26,4 +26,4 @@ large-model.apikey=sk-gQM7bpiRxaOl2emt0cBbF47481C5403885263eFeB95c7a8e
# \u652F\u4ED8\u56DE\u8C03\u5730\u5740
pay.domain.callback.url
=
https://model-link.gsstcloud.com/api/rest/payCallBackRest/payCallBack.json
# \u8C37\u6B4C\u767B\u5F55
google.client.id
=
698774957461-b3s1l98m7qjv5ilphvlo57gjhbs7fnfm.apps.googleusercontent.com
\ No newline at end of file
google.client.id
=
867985016759-n9qj00k174n9bibrtrqngvt89vbmnjrp.apps.googleusercontent.com
\ No newline at end of file
src/test/java/cn/com/poc/user/builder/LoginChannelTest.java
View file @
62d83597
...
...
@@ -4,8 +4,17 @@ package cn.com.poc.user.builder;
import
cn.com.poc.common.service.JudgeCodeService
;
import
cn.com.poc.user.dto.MemberLoginRequestDto
;
import
cn.com.poc.user.entity.MemberInfoEntity
;
import
cn.com.poc.user.service.BizMemberInfoService
;
import
cn.com.yict.framemax.core.config.Config
;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.com.yict.framemax.core.spring.SingleContextInitializer
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdToken
;
import
com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier
;
import
com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager
;
import
com.google.api.client.http.HttpTransport
;
import
com.google.api.client.http.apache.v2.ApacheHttpTransport
;
import
com.google.api.client.json.JsonFactory
;
import
com.google.api.client.json.gson.GsonFactory
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -20,6 +29,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
import
java.security.GeneralSecurityException
;
import
java.util.Collections
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
...
...
@@ -109,4 +123,19 @@ public class LoginChannelTest {
assertNotNull
(
memberInfoEntity
);
}
@Test
public
void
testGoogleLogin_idTokenVerify
()
throws
GeneralSecurityException
,
IOException
{
String
idTokenString
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ndtmg-NZm-Av1rVNEeR_82nTWsGBVKdtwwycVCMoK4p0D_J7KNGqz_dXwGxCwde0rIDp5XuJYhorp6dQUFirG0-sE9wcoiTiYuxvaf_3OkT0V9ew"
;
String
CLIENT_ID
=
Config
.
get
(
"google.client.id"
);
HttpTransport
transport
=
new
ApacheHttpTransport
();
JsonFactory
jsonFactory
=
new
GsonFactory
();
GooglePublicKeysManager
.
Builder
builder
=
new
GooglePublicKeysManager
.
Builder
(
transport
,
jsonFactory
);
builder
.
setPublicCertsEncodedUrl
(
"https://google-api.gsstcloud.com/oauth2/v1/certs"
);
GoogleIdTokenVerifier
verifier
=
new
GoogleIdTokenVerifier
.
Builder
(
builder
.
build
())
.
setAudience
(
Collections
.
singletonList
(
CLIENT_ID
))
.
build
();
GoogleIdToken
idToken
=
verifier
.
verify
(
idTokenString
);
System
.
out
.
println
(
idToken
);
}
}
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