本文整理汇总了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;
}
示例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;
}
}
示例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());
}
示例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;
}
示例5: setUp
import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Before
public void setUp() {
initProperties();
if (isInContainer()) {
oAuthService = OAuthServiceFactory.getOAuthService();
}
client = HttpClients.createDefault();
}
示例6: GoogleAppEngineAuthenticator
import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
public GoogleAppEngineAuthenticator() {
this(OAuthServiceFactory.getOAuthService(), UserServiceFactory.getUserService());
}
示例7: provideOauthService
import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
/** Provides the OAuthService instance. */
@Provides
OAuthService provideOauthService() {
return OAuthServiceFactory.getOAuthService();
}
示例8: getOauthService
import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOauthService() {
return OAuthServiceFactory.getOAuthService();
}
示例9: getOAuthService
import com.google.appengine.api.oauth.OAuthServiceFactory; //导入依赖的package包/类
@Provides
@Singleton
OAuthService getOAuthService() {
return OAuthServiceFactory.getOAuthService();
}
示例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);
}