当前位置: 首页>>代码示例>>Java>>正文


Java OAuthServiceFactory类代码示例

本文整理汇总了Java中com.google.appengine.api.oauth.OAuthServiceFactory的典型用法代码示例。如果您正苦于以下问题:Java OAuthServiceFactory类的具体用法?Java OAuthServiceFactory怎么用?Java OAuthServiceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OAuthServiceFactory类属于com.google.appengine.api.oauth包,在下文中一共展示了OAuthServiceFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEmail

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Override
public String getEmail() {
  
  try {
    OAuthService authService = OAuthServiceFactory.getOAuthService();
    
    User user = authService.getCurrentUser();
    
    if ( user != null ) {
      String email = user.getEmail();
      if ( email != null && email.length() != 0 ) {
        return "mailto:" + email;
      }
    }
  } catch ( OAuthRequestException e) {
    // ignore this -- just means it isn't an OAuth-mediated request.
  }
  return null;
}
 
开发者ID:opendatakit,项目名称:aggregate,代码行数:20,代码来源:GaeOutOfBandUserFetcher.java

示例2: authenticate

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@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;
    }
}
 
开发者ID:ciandt-dev,项目名称:tech-gallery,代码行数:23,代码来源:TechGalleryAuthenticator.java

示例3: doPost

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:21,代码来源:HelloServlet.java

示例4: getOAuthUser

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
/**
 * @return a non-null User object if somebody is authenticated
 */
private User getOAuthUser() throws OAuthRequestException {
    OAuthService oauth = OAuthServiceFactory.getOAuthService();
    String scope = "https://www.googleapis.com/auth/userinfo.email";
    Set<String> allowedClients = new HashSet<>();

    // see https://console.developers.google.com/apis/credentials?project=npackd
    // for more details about client IDs.
    // Npackd client 1.21
    allowedClients.add(
            "222041139141-vqv00o07p54ql0saefqkq59nupcgamih.apps.googleusercontent.com");

    User user = oauth.getCurrentUser(scope);
    if (user == null) {
        throw new OAuthRequestException("getCurrentUser() returned null");
    }

    String tokenAudience = oauth.getClientId(scope);
    if (!allowedClients.contains(tokenAudience)) {
        throw new OAuthRequestException("audience of token '" +
                tokenAudience +
                "' is not in allowed list " + allowedClients);
    }
    return user;
}
 
开发者ID:tim-lebedkov,项目名称:npackd-gae-web,代码行数:28,代码来源:NotifyAction.java

示例5: setUp

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Before
public void setUp() {
    initProperties();

    if (isInContainer()) {
        oAuthService = OAuthServiceFactory.getOAuthService();
    }

    client = HttpClients.createDefault();
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:11,代码来源:ClientSideWebAppFlowTest.java

示例6: GoogleAppEngineAuthenticator

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
public GoogleAppEngineAuthenticator() {
  this(OAuthServiceFactory.getOAuthService(), UserServiceFactory.getUserService());
}
 
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:4,代码来源:GoogleAppEngineAuthenticator.java

示例7: provideOauthService

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
/** Provides the OAuthService instance. */
@Provides
OAuthService provideOauthService() {
  return OAuthServiceFactory.getOAuthService();
}
 
开发者ID:google,项目名称:nomulus,代码行数:6,代码来源:AuthModule.java

示例8: getOauthService

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOauthService() {
  return OAuthServiceFactory.getOAuthService();
}
 
开发者ID:andrestesti,项目名称:blobstoretest,代码行数:6,代码来源:GaeServiceModule.java

示例9: getOAuthService

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOAuthService() {
    return OAuthServiceFactory.getOAuthService();
}
 
开发者ID:mikea,项目名称:appengine-java-tools,代码行数:6,代码来源:GaeModule.java

示例10: doGet

import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    logHeaders(req);

    String currentScope = null;
    String lastValidScope = null;
    user = null;
    errorOnScope = null;

    oAuthService = OAuthServiceFactory.getOAuthService();
    Enumeration<String> scopes = req.getHeaders("oauth-test-scope");
    try {
        // If any scopes are invalid, exception is thrown, then error message returned via errorOnScope.
        while (scopes.hasMoreElements()) {
            currentScope = scopes.nextElement();
            user = oAuthService.getCurrentUser(currentScope);
            lastValidScope = currentScope;
            log.info("Valid scope, user: " + user.getEmail());
        }

    } catch (OAuthRequestException e) {
        errorOnScope = e.toString() + " Invalid scope: " + currentScope;
        log.info(errorOnScope);
    }

    String env = SystemProperty.environment.value().toString();
    String responseMsg = env + ",";

    String method = req.getParameter("method");

    if (method == null) {
        resp.getWriter().print(responseMsg + "Error: Must set method parameter.");
        return;
    }

    if (method.equals("env")) {
        responseMsg += env;
        resp.getWriter().print(responseMsg);
        return;
    }

    responseMsg += callMethod(method, lastValidScope);
    resp.getWriter().print(responseMsg);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:44,代码来源:OAuthServiceServlet.java


注:本文中的com.google.appengine.api.oauth.OAuthServiceFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。