com.google.appengine.api.oauth.OAuthService Java Examples

The following examples show how to use com.google.appengine.api.oauth.OAuthService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TechGalleryAuthenticator.java    From tech-gallery with Apache License 2.0 6 votes vote down vote up
@Override
public User authenticate(HttpServletRequest req) {
    OAuthService authService = OAuthServiceFactory.getOAuthService();
    com.google.appengine.api.users.User currentUser;

    try {
      currentUser = authService.getCurrentUser(Constants.EMAIL_SCOPE);
      // Check current user..
      if(currentUser != null) {
        String email = currentUser.getEmail();
        // Check domain..
        if(isValidDomain(email) || isWhiteList(email)) {
          return new User(currentUser.getUserId(), currentUser.getEmail());
        }
      }
      throw new RestrictedDomainException(i18n.t("Authorization error"));
    }
    catch(OAuthRequestException  e) {
      log.log(Level.WARNING, "Error when trying to authenticate. Message: " + e.getMessage(), e);
      return null;
    }
}
 
Example #2
Source File: HelloServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void doPost(final HttpServletRequest req, final HttpServletResponse resp)
    throws IOException {

  resp.setContentType("text/plain");
  PrintWriter out = resp.getWriter();

  final String scope = "https://www.googleapis.com/auth/userinfo.email";
  OAuthService oauth = OAuthServiceFactory.getOAuthService();
  User user = null;
  try {
    user = oauth.getCurrentUser(scope);
  } catch (OAuthRequestException e) {
    getServletContext().log("Oauth error", e);
    out.print("auth error");
    return;
  }

  out.print("Hello world, welcome to Oauth2: " + user.getEmail());
}
 
Example #3
Source File: OAuthAuthenticationMechanism.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Inject
public OAuthAuthenticationMechanism(
    OAuthService oauthService,
    @Config("availableOauthScopes") ImmutableSet<String> availableOauthScopes,
    @Config("requiredOauthScopes") ImmutableSet<String> requiredOauthScopes,
    @Config("allowedOauthClientIds") ImmutableSet<String> allowedOauthClientIds) {
  this.oauthService = oauthService;
  this.availableOauthScopes = availableOauthScopes;
  this.requiredOauthScopes = requiredOauthScopes;
  this.allowedOauthClientIds = allowedOauthClientIds;
}
 
Example #4
Source File: GoogleAppEngineAuthenticator.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public GoogleAppEngineAuthenticator(OAuthService oauthService, UserService userService) {
  this.oauthService = oauthService;
  this.userService = userService;
}
 
Example #5
Source File: AuthModule.java    From nomulus with Apache License 2.0 4 votes vote down vote up
/** Provides the OAuthService instance. */
@Provides
OAuthService provideOauthService() {
  return OAuthServiceFactory.getOAuthService();
}