1
+ package com .gmi .nordborglab .browser .server .security ;
2
+
3
+ import org .springframework .social .oauth2 .AccessGrant ;
4
+ import org .springframework .social .oauth2 .GrantType ;
5
+ import org .springframework .social .oauth2 .OAuth2Operations ;
6
+ import org .springframework .social .oauth2 .OAuth2Parameters ;
7
+ import org .springframework .util .MultiValueMap ;
8
+
9
+ public class GoogleOAuth2TemplateWrapper implements OAuth2Operations {
10
+
11
+ private final OAuth2Operations oauth2Template ;
12
+
13
+ public GoogleOAuth2TemplateWrapper (OAuth2Operations oauth2Template ) {
14
+ this .oauth2Template = oauth2Template ;
15
+ }
16
+ private OAuth2Parameters fixRedirectUrl (OAuth2Parameters parameters ) {
17
+ String redirectUrl = parameters .getRedirectUri ();
18
+ if (redirectUrl .contains ("http" ) && !redirectUrl .contains ("localhost" )) {
19
+ redirectUrl = redirectUrl .replace ("http" , "https" );
20
+ }
21
+ parameters .setRedirectUri (redirectUrl );
22
+ return parameters ;
23
+ }
24
+
25
+ @ Override
26
+ public String buildAuthorizeUrl (OAuth2Parameters parameters ) {
27
+ return oauth2Template .buildAuthorizeUrl (fixRedirectUrl (parameters ));
28
+ }
29
+ @ Override
30
+ public String buildAuthorizeUrl (GrantType grantType , OAuth2Parameters parameters ) {
31
+ return oauth2Template .buildAuthorizeUrl (grantType , fixRedirectUrl (parameters ));
32
+ }
33
+ @ Override
34
+ public String buildAuthenticateUrl (OAuth2Parameters parameters ) {
35
+ return oauth2Template .buildAuthenticateUrl (fixRedirectUrl (parameters ));
36
+ }
37
+ @ Override
38
+ public String buildAuthenticateUrl (GrantType grantType , OAuth2Parameters parameters ) {
39
+ return oauth2Template .buildAuthenticateUrl (grantType , fixRedirectUrl (parameters ));
40
+ }
41
+ @ Override
42
+ public AccessGrant exchangeForAccess (String authorizationCode , String redirectUri ,
43
+ MultiValueMap <String , String > additionalParameters ) {
44
+ return oauth2Template .exchangeForAccess (authorizationCode , redirectUri , additionalParameters );
45
+ }
46
+ @ Override
47
+ public AccessGrant exchangeCredentialsForAccess (String username , String password ,
48
+ MultiValueMap <String , String > additionalParameters ) {
49
+ return oauth2Template .exchangeCredentialsForAccess (username , password , additionalParameters );
50
+ }
51
+ @ Override
52
+ public AccessGrant refreshAccess (String refreshToken , String scope ,
53
+ MultiValueMap <String , String > additionalParameters ) {
54
+ return oauth2Template .refreshAccess (refreshToken , scope , additionalParameters );
55
+ }
56
+ @ Override
57
+ public AccessGrant refreshAccess (String refreshToken , MultiValueMap <String , String > additionalParameters ) {
58
+ return oauth2Template .refreshAccess (refreshToken , additionalParameters );
59
+ }
60
+ @ Override
61
+ public AccessGrant authenticateClient () {
62
+ return oauth2Template .authenticateClient ();
63
+ }
64
+ @ Override
65
+ public AccessGrant authenticateClient (String scope ) {
66
+ return oauth2Template .authenticateClient (scope );
67
+ }
68
+ }
0 commit comments