1313 */
1414package com .example .appengine ;
1515
16+ import static com .google .appengine .api .utils .SystemProperty .environment ;
17+
1618import com .google .appengine .api .oauth .OAuthRequestException ;
1719import com .google .appengine .api .oauth .OAuthService ;
1820import com .google .appengine .api .oauth .OAuthServiceFactory ;
3335import javax .servlet .ServletResponse ;
3436import javax .servlet .http .HttpServletResponse ;
3537
36- import static com .google .appengine .api .utils .SystemProperty .environment ;
37-
3838/**
3939 * Filter to verify that request has a "Authorization: Bearer xxxx" header,
4040 * and check if xxxx is authorized to use this app.
@@ -55,11 +55,12 @@ public void init(final FilterConfig config) throws ServletException {
5555 @ Override
5656 public void doFilter (final ServletRequest servletReq , final ServletResponse servletResp ,
5757 final FilterChain chain ) throws IOException , ServletException {
58+ final String scope = "https://www.googleapis.com/auth/userinfo.email" ;
59+ Set <String > allowedClients = new HashSet <>();
60+
5861 HttpServletResponse resp = (HttpServletResponse ) servletResp ;
5962
6063 OAuthService oauth = OAuthServiceFactory .getOAuthService ();
61- final String scope = "https://www.googleapis.com/auth/userinfo.email" ;
62- Set <String > allowedClients = new HashSet <>();
6364
6465 allowedClients .add ("407408718192.apps.googleusercontent.com" ); // list of client ids to allow
6566 allowedClients .add ("755878275993-j4k7emq6rlupctce1c28enpcrr50vfo1.apps.googleusercontent.com" );
@@ -68,7 +69,7 @@ public void doFilter(final ServletRequest servletReq, final ServletResponse serv
6869 SystemProperty .Environment .Value env = environment .value ();
6970 if (env == SystemProperty .Environment .Value .Production ) { // APIs only work in Production
7071 try {
71- User user = oauth .getCurrentUser (scope ); // From "Authorization: Bearer" http req header
72+ User user = oauth .getCurrentUser (scope );
7273 String tokenAudience = oauth .getClientId (scope );
7374
7475 // The line below is commented out for privacy.
0 commit comments