13
13
*/
14
14
package com .example .appengine ;
15
15
16
+ import static com .google .appengine .api .utils .SystemProperty .environment ;
17
+
16
18
import com .google .appengine .api .oauth .OAuthRequestException ;
17
19
import com .google .appengine .api .oauth .OAuthService ;
18
20
import com .google .appengine .api .oauth .OAuthServiceFactory ;
33
35
import javax .servlet .ServletResponse ;
34
36
import javax .servlet .http .HttpServletResponse ;
35
37
36
- import static com .google .appengine .api .utils .SystemProperty .environment ;
37
-
38
38
/**
39
39
* Filter to verify that request has a "Authorization: Bearer xxxx" header,
40
40
* and check if xxxx is authorized to use this app.
@@ -55,11 +55,12 @@ public void init(final FilterConfig config) throws ServletException {
55
55
@ Override
56
56
public void doFilter (final ServletRequest servletReq , final ServletResponse servletResp ,
57
57
final FilterChain chain ) throws IOException , ServletException {
58
+ final String scope = "https://www.googleapis.com/auth/userinfo.email" ;
59
+ Set <String > allowedClients = new HashSet <>();
60
+
58
61
HttpServletResponse resp = (HttpServletResponse ) servletResp ;
59
62
60
63
OAuthService oauth = OAuthServiceFactory .getOAuthService ();
61
- final String scope = "https://www.googleapis.com/auth/userinfo.email" ;
62
- Set <String > allowedClients = new HashSet <>();
63
64
64
65
allowedClients .add ("407408718192.apps.googleusercontent.com" ); // list of client ids to allow
65
66
allowedClients .add ("755878275993-j4k7emq6rlupctce1c28enpcrr50vfo1.apps.googleusercontent.com" );
@@ -68,7 +69,7 @@ public void doFilter(final ServletRequest servletReq, final ServletResponse serv
68
69
SystemProperty .Environment .Value env = environment .value ();
69
70
if (env == SystemProperty .Environment .Value .Production ) { // APIs only work in Production
70
71
try {
71
- User user = oauth .getCurrentUser (scope ); // From "Authorization: Bearer" http req header
72
+ User user = oauth .getCurrentUser (scope );
72
73
String tokenAudience = oauth .getClientId (scope );
73
74
74
75
// The line below is commented out for privacy.
0 commit comments