本文整理汇总了Java中com.google.api.services.oauth2.model.Userinfo类的典型用法代码示例。如果您正苦于以下问题:Java Userinfo类的具体用法?Java Userinfo怎么用?Java Userinfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Userinfo类属于com.google.api.services.oauth2.model包,在下文中一共展示了Userinfo类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doView
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
@Override
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
AccessToken accessToken = getAccessToken();
final Oauth2 service = getOAuthProvider().getAuthorizedSocialApiObject(accessToken, Oauth2.class);
Userinfo userInfo = new GooglePortletRequest<Userinfo>(request, response, getPortletContext(), getOAuthProvider(),
REQUIRED_SCOPE) {
@Override
protected Userinfo invokeRequest() throws IOException {
return service.userinfo().v2().me().get().execute();
}
}.executeRequest();
if (userInfo != null) {
request.setAttribute(GOOGLE_USER_INFO, userInfo);
}
PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/google/userinfo.jsp");
prd.include(request, response);
}
开发者ID:exo-samples,项目名称:docs-samples,代码行数:23,代码来源:GoogleUserInfoPortlet.java
示例2: getUserInfo
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
/**
* Send a request to the UserInfo API to retrieve the user's
* information.
*
* @param credentials OAuth 2.0 credentials to authorize the request.
* @return User's information.
* @throws NoUserIdException An error occurred.
*/
static Userinfo getUserInfo(Credential credentials)
throws NoUserIdException {
Oauth2 userInfoService = new Oauth2.Builder(new NetHttpTransport(),
new JacksonFactory(), credentials).build();
Userinfo userInfo = null;
try {
userInfo = userInfoService.userinfo().get().execute();
} catch (IOException e) {
System.err.println("An error occurred: " + e);
}
if (userInfo != null && userInfo.getId() != null) {
return userInfo;
} else {
throw new NoUserIdException();
}
}
开发者ID:mba811,项目名称:loli.io,代码行数:25,代码来源:GDriveAPI.java
示例3: getUserInfo
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
protected Userinfo getUserInfo(Credential credentials)
throws NoSuchUserIdException {
Oauth2.Builder builder = new Oauth2.Builder(
new NetHttpTransport(), new JacksonFactory(), credentials);
Oauth2 oauth2 = builder.build();
Userinfo userInfo = null;
try {
userInfo = oauth2.userinfo().get().execute();
}
catch (IOException e) {
System.err.println("An error occurred: " + e);
}
if ((userInfo != null) && (userInfo.getId() != null)) {
return userInfo;
}
else {
throw new NoSuchUserIdException();
}
}
开发者ID:sergiogonzalez,项目名称:google-login-hook,代码行数:25,代码来源:GoogleOAuth.java
示例4: handleCallbackIfRequired
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
/**
* If OAuth2 redirect callback is invoked and there is a code query param,
* retrieve user credentials and profile. Then, redirect to the home page.
* @param req Request object.
* @param resp Response object.
* @throws IOException
*/
protected boolean handleCallbackIfRequired(HttpServletRequest req,
HttpServletResponse resp) throws IOException {
String code = req.getParameter("code");
if (code != null) {
// retrieve new credentials with code
Credential credential = credentialManager.retrieve(code);
// request userinfo
Oauth2 service = getOauth2Service(credential);
Userinfo about = service.userinfo().get().execute();
String id = about.getId();
credentialManager.save(id, credential);
req.getSession().setAttribute(KEY_SESSION_USERID, id);
String redirect = (String) req.getSession().getAttribute(KEY_SESSION_REDIRECT);
req.getSession().setAttribute(KEY_SESSION_REDIRECT, null);
if (redirect != null) {
resp.sendRedirect(redirect);
} else {
resp.sendRedirect("?");
}
return true;
}
return false;
}
开发者ID:googlearchive,项目名称:drivemarks,代码行数:32,代码来源:BaseServlet.java
示例5: createUserProfile
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
private static UserProfile createUserProfile(User user) throws IOException {
UserProfile userProfile = UserProfile.create(user);
try {
Userinfo userInfo = GoogleApiUtils.getOauth2(userProfile.getEmail())
.userinfo()
.get()
.execute();
userProfile.setFullName(userInfo.getName());
} catch (GoogleJsonResponseException e) {
int statusCode = e.getDetails().getCode();
if (statusCode == 401 || statusCode == 403) {
// TODO: Log a warning and continue
} else {
throw e;
}
}
return userProfile;
}
开发者ID:openmash,项目名称:mashmesh,代码行数:21,代码来源:RequireProfileFilter.java
示例6: addUser
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
protected User addUser(
HttpSession session, long companyId, Userinfo userinfo)
throws Exception {
long creatorUserId = 0;
boolean autoPassword = true;
String password1 = StringPool.BLANK;
String password2 = StringPool.BLANK;
boolean autoScreenName = true;
String screenName = StringPool.BLANK;
String emailAddress = userinfo.getEmail();
String openId = StringPool.BLANK;
Locale locale = LocaleUtil.getDefault();
String firstName = userinfo.getGivenName();
String middleName = StringPool.BLANK;
String lastName = userinfo.getFamilyName();
int prefixId = 0;
int suffixId = 0;
boolean male = Validator.equals(userinfo.getGender(), "male");
int birthdayMonth = Calendar.JANUARY;
int birthdayDay = 1;
int birthdayYear = 1970;
String jobTitle = StringPool.BLANK;
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
long[] userGroupIds = null;
boolean sendEmail = true;
ServiceContext serviceContext = new ServiceContext();
User user = UserLocalServiceUtil.addUser(
creatorUserId, companyId, autoPassword, password1, password2,
autoScreenName, screenName, emailAddress, 0, openId,
locale, firstName, middleName, lastName, prefixId, suffixId, male,
birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds,
organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);
user = UserLocalServiceUtil.updateLastLogin(
user.getUserId(), user.getLoginIP());
user = UserLocalServiceUtil.updatePasswordReset(
user.getUserId(), false);
user = UserLocalServiceUtil.updateEmailAddressVerified(
user.getUserId(), true);
session.setAttribute("GOOGLE_USER_EMAIL_ADDRESS", emailAddress);
return user;
}
开发者ID:sergiogonzalez,项目名称:google-login-hook,代码行数:52,代码来源:GoogleOAuth.java
示例7: setGoogleCredentials
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
protected User setGoogleCredentials(
HttpSession session, long companyId, Userinfo userinfo)
throws Exception {
if (userinfo == null) {
return null;
}
User user = null;
String emailAddress = userinfo.getEmail();
if ((user == null) && Validator.isNotNull(emailAddress)) {
user = UserLocalServiceUtil.fetchUserByEmailAddress(
companyId, emailAddress);
if ((user != null) &&
(user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE)) {
session.setAttribute(
"GOOGLE_USER_EMAIL_ADDRESS", emailAddress);
}
}
if (user != null) {
if (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE) {
session.setAttribute(
"GOOGLE_INCOMPLETE_USER_ID", userinfo.getId());
user.setEmailAddress(userinfo.getEmail());
user.setFirstName(userinfo.getGivenName());
user.setLastName(userinfo.getFamilyName());
return user;
}
user = updateUser(user, userinfo);
}
else {
user = addUser(session, companyId, userinfo);
}
return user;
}
开发者ID:sergiogonzalez,项目名称:google-login-hook,代码行数:45,代码来源:GoogleOAuth.java
示例8: updateUser
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
protected User updateUser(User user, Userinfo userinfo)
throws Exception {
String emailAddress = userinfo.getEmail();
String firstName = userinfo.getGivenName();
String lastName = userinfo.getFamilyName();
boolean male = Validator.equals(userinfo.getGender(), "male");
if (emailAddress.equals(user.getEmailAddress()) &&
firstName.equals(user.getFirstName()) &&
lastName.equals(user.getLastName()) && (male == user.isMale())) {
return user;
}
Contact contact = user.getContact();
Calendar birthdayCal = CalendarFactoryUtil.getCalendar();
birthdayCal.setTime(contact.getBirthday());
int birthdayMonth = birthdayCal.get(Calendar.MONTH);
int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
int birthdayYear = birthdayCal.get(Calendar.YEAR);
long[] groupIds = null;
long[] organizationIds = null;
long[] roleIds = null;
List<UserGroupRole> userGroupRoles = null;
long[] userGroupIds = null;
ServiceContext serviceContext = new ServiceContext();
if (!StringUtil.equalsIgnoreCase(
emailAddress, user.getEmailAddress())) {
UserLocalServiceUtil.updateEmailAddress(
user.getUserId(), StringPool.BLANK, emailAddress, emailAddress);
}
UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true);
return UserLocalServiceUtil.updateUser(
user.getUserId(), StringPool.BLANK, StringPool.BLANK,
StringPool.BLANK, false, user.getReminderQueryQuestion(),
user.getReminderQueryAnswer(), user.getScreenName(), emailAddress,
0, user.getOpenId(), user.getLanguageId(),
user.getTimeZoneId(), user.getGreeting(), user.getComments(),
firstName, user.getMiddleName(), lastName, contact.getPrefixId(),
contact.getSuffixId(), male, birthdayMonth, birthdayDay,
birthdayYear, contact.getSmsSn(), contact.getAimSn(),
contact.getFacebookSn(), contact.getIcqSn(), contact.getJabberSn(),
contact.getMsnSn(), contact.getMySpaceSn(), contact.getSkypeSn(),
contact.getTwitterSn(), contact.getYmSn(), contact.getJobTitle(),
groupIds, organizationIds, roleIds, userGroupRoles, userGroupIds,
serviceContext);
}
开发者ID:sergiogonzalez,项目名称:google-login-hook,代码行数:58,代码来源:GoogleOAuth.java
示例9: getUserInfo
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
public User getUserInfo(String userId, Credential credential) throws IOException {
Oauth2 service = getOauth2Service(credential);
Userinfo userInfo = service.userinfo().get().execute();
return new User(userInfo.getEmail(), userInfo.getLink(), userInfo.getPicture());
}
开发者ID:aleksz,项目名称:driveddoc,代码行数:6,代码来源:UserService.java
示例10: execute
import com.google.api.services.oauth2.model.Userinfo; //导入依赖的package包/类
public String execute(
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);
String cmd = ParamUtil.getString(request, Constants.CMD);
String redirectUri = PortalUtil.getPortalURL(request) + _REDIRECT_URI;
if (cmd.equals("login")) {
GoogleAuthorizationCodeFlow flow = getFlow();
GoogleAuthorizationCodeRequestUrl
googleAuthorizationCodeRequestUrl = flow.newAuthorizationUrl();
googleAuthorizationCodeRequestUrl.setRedirectUri(redirectUri);
String url = googleAuthorizationCodeRequestUrl.build();
response.sendRedirect(url);
}
else if (cmd.equals("token")) {
HttpSession session = request.getSession();
String code = ParamUtil.getString(request, "code");
if (Validator.isNotNull(code)) {
Credential credential = exchangeCode(code, redirectUri);
Userinfo userinfo = getUserInfo(credential);
User user = setGoogleCredentials(
session, themeDisplay.getCompanyId(), userinfo);
if ((user != null) &&
(user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE)) {
redirectUpdateAccount(request, response, user);
return null;
}
PortletURL portletURL = PortletURLFactoryUtil.create(
request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(),
PortletRequest.RENDER_PHASE);
portletURL.setWindowState(LiferayWindowState.POP_UP);
portletURL.setParameter(
"struts_action", "/login/login_redirect");
response.sendRedirect(portletURL.toString());
}
}
return null;
}
开发者ID:sergiogonzalez,项目名称:google-login-hook,代码行数:60,代码来源:GoogleOAuth.java
注:本文中的com.google.api.services.oauth2.model.Userinfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论