本文整理汇总了Java中com.google.gerrit.extensions.auth.oauth.OAuthToken.getToken方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthToken.getToken方法的具体用法?Java OAuthToken.getToken怎么用?Java OAuthToken.getToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gerrit.extensions.auth.oauth.OAuthToken
的用法示例。
在下文中一共展示了OAuthToken.getToken方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthTokenInfo apply(AccountResource rsrc)
throws AuthException, ResourceNotFoundException {
if (self.get() != rsrc.getUser()) {
throw new AuthException("not allowed to get access token");
}
Account a = rsrc.getUser().getAccount();
OAuthToken accessToken = tokenCache.get(a.getId());
if (accessToken == null) {
throw new ResourceNotFoundException();
}
OAuthTokenInfo accessTokenInfo = new OAuthTokenInfo();
accessTokenInfo.username = a.getUserName();
accessTokenInfo.resourceHost = getHostName(canonicalWebUrlProvider.get());
accessTokenInfo.accessToken = accessToken.getToken();
accessTokenInfo.providerId = accessToken.getProviderId();
accessTokenInfo.expiresAt = Long.toString(accessToken.getExpiresAt());
accessTokenInfo.type = BEARER_TYPE;
return accessTokenInfo;
}
示例2: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
if (userJson.isJsonObject()) {
JsonObject jsonObject = userJson.getAsJsonObject();
JsonObject userObject = jsonObject.getAsJsonObject("user");
if (userObject == null || userObject.isJsonNull()) {
throw new IOException("Response doesn't contain 'user' field");
}
JsonElement usernameElement = userObject.get("username");
String username = usernameElement.getAsString();
JsonElement displayName = jsonObject.get("display_name");
return new OAuthUserInfo(
BITBUCKET_PROVIDER_PREFIX + username,
username,
null,
displayName == null || displayName.isJsonNull() ? null : displayName.getAsString(),
fixLegacyUserId ? username : null);
}
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
示例3: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
final String protectedResourceUrl = String.format(PROTECTED_RESOURCE_URL, rootUrl);
OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson = JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
JsonObject jsonObject = userJson.getAsJsonObject();
if (jsonObject == null || jsonObject.isJsonNull()) {
throw new IOException("Response doesn't contain 'user' field" + jsonObject);
}
JsonElement id = jsonObject.get("id");
JsonElement username = jsonObject.get("username");
JsonElement email = jsonObject.get("email");
JsonElement name = jsonObject.get("name");
return new OAuthUserInfo(
GITLAB_PROVIDER_PREFIX + id.getAsString(),
username == null || username.isJsonNull() ? null : username.getAsString(),
email == null || email.isJsonNull() ? null : email.getAsString(),
name == null || name.isJsonNull() ? null : name.getAsString(),
null);
}
示例4: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != HttpServletResponse.SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson =
OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
if (userJson.isJsonObject()) {
JsonObject jsonObject = userJson.getAsJsonObject();
JsonElement id = jsonObject.get("id");
if (id == null || id.isJsonNull()) {
throw new IOException(String.format("Response doesn't contain id field"));
}
JsonElement email = jsonObject.get("email");
JsonElement name = jsonObject.get("name");
JsonElement login = jsonObject.get("login");
return new OAuthUserInfo(
GITHUB_PROVIDER_PREFIX + id.getAsString(),
login == null || login.isJsonNull() ? null : login.getAsString(),
email == null || email.isJsonNull() ? null : email.getAsString(),
name == null || name.isJsonNull() ? null : name.getAsString(),
fixLegacyUserId ? id.getAsString() : null);
}
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
示例5: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
String oauthToken = token.getToken();
GitHub hub = GitHub.connectUsingOAuth(oauthToken);
GHMyself myself = hub.getMyself();
String login = myself.getLogin();
return new OAuthUserInfo(
ExternalId.SCHEME_GERRIT + login, login, myself.getEmail(), myself.getName(), null);
}
示例6: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
final String protectedResourceUrl = String.format(PROTECTED_RESOURCE_URL, rootUrl);
OAuthRequest request = new OAuthRequest(Verb.GET, protectedResourceUrl);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != HttpServletResponse.SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
JsonElement userJson =
OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (!userJson.isJsonObject()) {
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
JsonObject jsonObject = userJson.getAsJsonObject();
JsonElement id = jsonObject.get("id");
if (id == null || id.isJsonNull()) {
throw new IOException(String.format("CAS response missing id: %s", response.getBody()));
}
JsonElement attrListJson = jsonObject.get("attributes");
if (attrListJson == null) {
throw new IOException(
String.format("CAS response missing attributes: %s", response.getBody()));
}
String email = null, name = null, login = null;
if (attrListJson != null && attrListJson.isJsonArray()) {
// It is possible for CAS to be configured to not return any attributes (email, name, login), in which case,
// CAS returns an empty JSON object "attributes":{}, rather than "null" or an empty JSON array "attributes": []
JsonArray attrJson = attrListJson.getAsJsonArray();
for (JsonElement elem : attrJson) {
if (elem == null || !elem.isJsonObject()) {
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", elem));
}
JsonObject obj = elem.getAsJsonObject();
String property = getStringElement(obj, "email");
if (property != null) email = property;
property = getStringElement(obj, "name");
if (property != null) name = property;
property = getStringElement(obj, "login");
if (property != null) login = property;
}
}
return new OAuthUserInfo(
CAS_PROVIDER_PREFIX + id.getAsString(),
login,
email,
name,
fixLegacyUserId ? id.getAsString() : null);
}
示例7: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != HttpServletResponse.SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson =
OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
if (userJson.isJsonObject()) {
JsonObject jsonObject = userJson.getAsJsonObject();
JsonElement id = jsonObject.get("id");
if (id == null || id.isJsonNull()) {
throw new IOException(String.format("Response doesn't contain id field"));
}
JsonElement email = jsonObject.get("email");
JsonElement name = jsonObject.get("name");
String login = null;
if (domains.size() > 0) {
boolean domainMatched = false;
JsonObject jwtToken = retrieveJWTToken(token);
String hdClaim = retrieveHostedDomain(jwtToken);
for (String domain : domains) {
if (domain.equalsIgnoreCase(hdClaim)) {
domainMatched = true;
break;
}
}
if (!domainMatched) {
// TODO(davido): improve error reporting in OAuth extension point
log.error("Error: hosted domain validation failed: {}", Strings.nullToEmpty(hdClaim));
return null;
}
}
if (useEmailAsUsername && !email.isJsonNull()) {
login = email.getAsString().split("@")[0];
}
return new OAuthUserInfo(
GOOGLE_PROVIDER_PREFIX + id.getAsString() /*externalId*/,
login /*username*/,
email == null || email.isJsonNull() ? null : email.getAsString() /*email*/,
name == null || name.isJsonNull() ? null : name.getAsString() /*displayName*/,
fixLegacyUserId ? id.getAsString() : null /*claimedIdentity*/);
}
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}
示例8: getUserInfo
import com.google.gerrit.extensions.auth.oauth.OAuthToken; //导入方法依赖的package包/类
@Override
public OAuthUserInfo getUserInfo(OAuthToken token) throws IOException {
OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
Token t = new Token(token.getToken(), token.getSecret(), token.getRaw());
request.addQuerystringParameter(FIELDS_QUERY, FIELDS);
service.signRequest(t, request);
Response response = request.send();
if (response.getCode() != HttpServletResponse.SC_OK) {
throw new IOException(
String.format(
"Status %s (%s) for request %s",
response.getCode(), response.getBody(), request.getUrl()));
}
JsonElement userJson =
OutputFormat.JSON.newGson().fromJson(response.getBody(), JsonElement.class);
if (log.isDebugEnabled()) {
log.debug("User info response: {}", response.getBody());
}
if (userJson.isJsonObject()) {
JsonObject jsonObject = userJson.getAsJsonObject();
JsonElement id = jsonObject.get("id");
if (id == null || id.isJsonNull()) {
throw new IOException(String.format("Response doesn't contain id field"));
}
JsonElement email = jsonObject.get("email");
JsonElement name = jsonObject.get("name");
// Heads up!
// Lets keep `login` equal to `email`, since `username` field is
// deprecated for Facebook API versions v2.0 and higher
JsonElement login = jsonObject.get("email");
return new OAuthUserInfo(
FACEBOOK_PROVIDER_PREFIX + id.getAsString(),
login == null || login.isJsonNull() ? null : login.getAsString(),
email == null || email.isJsonNull() ? null : email.getAsString(),
name == null || name.isJsonNull() ? null : name.getAsString(),
null);
}
throw new IOException(String.format("Invalid JSON '%s': not a JSON Object", userJson));
}