Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth2 updates, Guestbook #172

Merged
merged 8 commits into from
Apr 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More check style goodness.
  • Loading branch information
Les Vogel committed Apr 20, 2016
commit e110bb3f03e1d33e3a9d4b560e5b80d5cf477988
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package com.example.appengine;

import static com.google.appengine.api.utils.SystemProperty.environment;

import com.google.appengine.api.oauth.OAuthRequestException;
import com.google.appengine.api.oauth.OAuthService;
import com.google.appengine.api.oauth.OAuthServiceFactory;
Expand All @@ -33,8 +35,6 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import static com.google.appengine.api.utils.SystemProperty.environment;

/**
* Filter to verify that request has a "Authorization: Bearer xxxx" header,
* and check if xxxx is authorized to use this app.
Expand All @@ -55,11 +55,12 @@ public void init(final FilterConfig config) throws ServletException {
@Override
public void doFilter(final ServletRequest servletReq, final ServletResponse servletResp,
final FilterChain chain) throws IOException, ServletException {
final String scope = "https://www.googleapis.com/auth/userinfo.email";
Set<String> allowedClients = new HashSet<>();

HttpServletResponse resp = (HttpServletResponse) servletResp;

OAuthService oauth = OAuthServiceFactory.getOAuthService();
final String scope = "https://www.googleapis.com/auth/userinfo.email";
Set<String> allowedClients = new HashSet<>();

allowedClients.add("407408718192.apps.googleusercontent.com"); // list of client ids to allow
allowedClients.add("755878275993-j4k7emq6rlupctce1c28enpcrr50vfo1.apps.googleusercontent.com");
Expand All @@ -68,7 +69,7 @@ public void doFilter(final ServletRequest servletReq, final ServletResponse serv
SystemProperty.Environment.Value env = environment.value();
if (env == SystemProperty.Environment.Value.Production) { // APIs only work in Production
try {
User user = oauth.getCurrentUser(scope); // From "Authorization: Bearer" http req header
User user = oauth.getCurrentUser(scope);
String tokenAudience = oauth.getClientId(scope);

// The line below is commented out for privacy.
Expand Down