本文整理汇总了Java中com.google.appengine.api.oauth.OAuthService类的典型用法代码示例。如果您正苦于以下问题:Java OAuthService类的具体用法?Java OAuthService怎么用?Java OAuthService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthService类属于com.google.appengine.api.oauth包,在下文中一共展示了OAuthService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getEmail
import com.google.appengine.api.oauth.OAuthService; //导入依赖的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.OAuthService; //导入依赖的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.OAuthService; //导入依赖的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.OAuthService; //导入依赖的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: OAuthAuthenticationMechanism
import com.google.appengine.api.oauth.OAuthService; //导入依赖的package包/类
@VisibleForTesting
@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;
}
开发者ID:google,项目名称:nomulus,代码行数:13,代码来源:OAuthAuthenticationMechanism.java
示例6: GoogleAppEngineAuthenticator
import com.google.appengine.api.oauth.OAuthService; //导入依赖的package包/类
public GoogleAppEngineAuthenticator(OAuthService oauthService, UserService userService) {
this.oauthService = oauthService;
this.userService = userService;
}
开发者ID:cloudendpoints,项目名称:endpoints-java,代码行数:5,代码来源:GoogleAppEngineAuthenticator.java
示例7: provideOauthService
import com.google.appengine.api.oauth.OAuthService; //导入依赖的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.OAuthService; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOauthService() {
return OAuthServiceFactory.getOAuthService();
}
开发者ID:andrestesti,项目名称:blobstoretest,代码行数:6,代码来源:GaeServiceModule.java
示例9: OAuthFilter
import com.google.appengine.api.oauth.OAuthService; //导入依赖的package包/类
@Inject
OAuthFilter(OAuthService oauth) {
this.oauth = oauth;
}
开发者ID:andrestesti,项目名称:blobstoretest,代码行数:5,代码来源:OAuthFilter.java
示例10: getOAuthService
import com.google.appengine.api.oauth.OAuthService; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOAuthService() {
return OAuthServiceFactory.getOAuthService();
}
开发者ID:mikea,项目名称:appengine-java-tools,代码行数:6,代码来源:GaeModule.java
注:本文中的com.google.appengine.api.oauth.OAuthService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论