本文整理匯總了Java中org.scribe.model.OAuthRequest.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java OAuthRequest.addHeader方法的具體用法?Java OAuthRequest.addHeader怎麽用?Java OAuthRequest.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.scribe.model.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.addHeader方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: send
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
private String send(Verb verb, String params) throws Exception {
String url = apiUrl + ((params != null) ? params : "");
OAuthRequest request = new OAuthRequest(verb, url);
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, apiAccessToken);
// For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23
StringBuilder sb = new StringBuilder();
sb.append("Bearer ");
sb.append(apiAccessToken);
request.addHeader("Authorization", sb.toString());
if (LOG.isDebugEnabled()) {
LOG.debug("Yammer request url: {}", request.getCompleteUrl());
}
Response response = request.send();
if (response.isSuccessful()) {
return response.getBody();
} else {
throw new Exception(String.format("Failed to poll %s. Got response code %s and body: %s", getApiUrl(), response.getCode(), response.getBody()));
}
}
示例2: appendSignature
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
示例3: appendSignature
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
private void appendSignature(OAuthRequest request)
{
switch (config.getSignatureType())
{
case Header:
config.log("using Http Header signature");
String oauthHeader = api.getHeaderExtractor().extract(request);
request.addHeader(OAuthConstants.HEADER, oauthHeader);
break;
case QueryString:
config.log("using Querystring signature");
for (Map.Entry<String, String> entry : request.getOauthParameters().entrySet())
{
request.addQuerystringParameter(entry.getKey(), entry.getValue());
}
break;
}
}
示例4: getAccessToken
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public Token getAccessToken(Token token, Verifier verifier) {
OAuthRequest request =
new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addHeader("Authorization", prepareAuthorizationHeaderValue());
request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_VALUE);
request.addBodyParameter(CODE, verifier.getValue());
Response response = request.send();
if (response.getCode() == SC_OK) {
Token t = api.getAccessTokenExtractor().extract(response.getBody());
return new Token(t.getToken(), config.getApiSecret());
}
throw new OAuthException(
String.format(
"Error response received: %s, HTTP status: %s",
response.getBody(), response.getCode()));
}
示例5: getAccessTokenByAuthCode
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
/**
* Receive oauth2 token from authentication server and store it in the session context
*
* @param authorizationCode from authentication server
* @return oauth2 token
* @throws IOException
*/
@Override
public OAuth2AccessToken getAccessTokenByAuthCode(String authorizationCode) throws ParseException {
LOGGER.info("get oauth2 access token", TokenServiceImpl.class);
OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, ACCESS_TOKEN_URI);
oAuthRequest.addHeader("Content-Type", HEADER_CONTENT_TYPE);
oAuthRequest.addHeader("Authorization", HEADER_AUTHORIZATION_TYPE + Base64.encodeBase64String(new String(CLIENT_ID + ":" + CLIENT_SECRET).getBytes()));
oAuthRequest.setCharset(HEADER_CHAR_SET_TYPE);
oAuthRequest.addBodyParameter("grant_type", AUTHORIZATION_CODE_GRANT_TYPE);
oAuthRequest.addBodyParameter("code", authorizationCode);
LOGGER.info("send request for access token", TokenServiceImpl.class);
String accessTokenResponse = oAuthRequest.send().getBody();
if (accessTokenResponse != null) {
LOGGER.info("successfully received authorization token");
// store accessToken in session context
this.accessToken = new DefaultOAuth2AccessToken(new JSONObject(accessTokenResponse).get("access_token").toString());
((DefaultOAuth2AccessToken) this.accessToken).setRefreshToken(new DefaultOAuth2RefreshToken(new JSONObject(accessTokenResponse).get("refresh_token").toString()));
((DefaultOAuth2AccessToken) this.accessToken).setExpiration((new Date(System.currentTimeMillis() + (Long
.valueOf(new JSONObject(accessTokenResponse).get("expires_in").toString()) * 60000))));
String idToken = new JSONObject(accessTokenResponse).get("id_token").toString();
this.jwtDTO = parseJWTToken(idToken);
this.userId = this.jwtDTO.getUserId();
} else {
LOGGER.warn("failed to get authorization token", TokenServiceImpl.class);
}
return accessToken;
}
示例6: refreshToken
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
/**
* Obtain a new token by refresh token
*/
@Override
public void refreshToken() {
if (this.accessToken.getRefreshToken() != null) {
OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, ACCESS_TOKEN_URI);
oAuthRequest.addHeader("Content-Type", HEADER_CONTENT_TYPE);
oAuthRequest.addHeader("Authorization", HEADER_AUTHORIZATION_TYPE + Base64.encodeBase64String(new String(CLIENT_ID + ":" + CLIENT_SECRET).getBytes()));
oAuthRequest.setCharset(HEADER_CHAR_SET_TYPE);
oAuthRequest.addBodyParameter("grant_type", REFRESH_TOKEN_GRANT_TYPE);
oAuthRequest.addBodyParameter("refresh_token", getAccessTokenFromContext().getRefreshToken().getValue().toString());
oAuthRequest.addBodyParameter("scope", CLIENT_ID + "." + propertySources.getTradeshiftAppVersion());
LOGGER.info("send request for access token by refresh token", TokenServiceImpl.class);
String accessTokenResponse = oAuthRequest.send().getBody();
if (accessTokenResponse != null) {
LOGGER.info("successfully received authorization token by refresh token");
// store accessToken in session context
this.accessToken = new DefaultOAuth2AccessToken(new JSONObject(accessTokenResponse).get("access_token").toString());
((DefaultOAuth2AccessToken) this.accessToken).setExpiration((new Date(System.currentTimeMillis() + Long.valueOf(new JSONObject(accessTokenResponse).get("expires_in").toString()))));
} else {
LOGGER.warn("failed to get authorization token by refresh token", TokenServiceImpl.class);
}
} else {
LOGGER.error("Refresh token doesn't exist", TokenServiceImpl.class);
}
}
示例7: signRequest
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public void signRequest(Token accessToken, OAuthRequest request) {
switch (config.getSignatureType()) {
case Header:
config.log("using Http Header signature");
request.addHeader(OAuthConstants.HEADER, bearerName + " " + accessToken.getToken());
break;
case QueryString:
config.log("using Querystring signature");
request.addQuerystringParameter(OAuthConstants.ACCESS_TOKEN, accessToken.getToken());
break;
}
}
示例8: getAttributeProfile
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public Response getAttributeProfile(long customerId, int clientId, String attribute) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = LinkedInCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
OAuthRequest request = new OAuthRequest(Verb.GET, LinkedInAppResource.API_BASIC_PROFILE_URI + ":(" + attribute + ")");
request.addHeader("x-li-format", "json");
OAuthService service = client.getLinkHandler().getServiceProvider();
service.signRequest(client.getLinkHandler().getAccessToken(), request);
org.scribe.model.Response response = request.send();
return Response.status(Response.Status.OK).entity(response.getBody()).build();
}
示例9: post
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public String post(String url, byte[] payload, Map.Entry<String, String>... params) {
OAuthRequest request = new OAuthRequest(Verb.POST, url);
if (params != null) {
this.addBodyParams(request, params);
}
request.addPayload(payload);
request.addHeader("Content-Type", "application/json");
this.service.signRequest(this.accesToken, request);
Response r = request.send();
return r.getBody();
}
示例10: put
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public void put(String url, byte[] payload, Map.Entry<String, String>... params) {
OAuthRequest request = new OAuthRequest(Verb.PUT, url);
if (params != null) {
this.addBodyParams(request, params);
}
request.addPayload(payload);
request.addHeader("Content-Type", "application/json");
this.service.signRequest(this.accesToken, request);
Response r = request.send();
if (!(r.getCode() == 204)) {
throw new PutException("Invalid return code", r.getCode());
}
}
示例11: getBasicProfile
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public Response getBasicProfile(long customerId, int clientId) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = LinkedInCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
JsonParser jsonParser = new JsonParser();
// to get response and get the body of response
OAuthRequest request = new OAuthRequest(Verb.GET, LinkedInAppResource.API_BASIC_PROFILE_URI);
// set the header format to json
request.addHeader("x-li-format", "json");
OAuthService service = client.getLinkHandler().getServiceProvider();
service.signRequest(client.getLinkHandler().getAccessToken(), request);
org.scribe.model.Response response = request.send();
// convert the string result to a json object
JSONObject profileJsonObj = new JSONObject(response.getBody());
// get a json object inside another json object
JSONObject profileUrlJsonObj = profileJsonObj.getJSONObject("siteStandardProfileRequest");
// get json values from a json object of LinkedIn API
jsonParser.parseJsonOfBasicProfile(profileJsonObj, profileUrlJsonObj);
client.getProfile().setBasicProfile(jsonParser.getBasicProfile());
return Response.status(Response.Status.OK).entity(client.getProfile().getBasicProfile()).type(MediaType.APPLICATION_JSON_TYPE).build();
}
示例12: getDetaiedProfile
import org.scribe.model.OAuthRequest; //導入方法依賴的package包/類
@Override
public Response getDetaiedProfile(long customerId, int clientId) {
if (!IdPool.clientInList(customerId, clientId)) {
clientNotFoundMsg.setCustomerId(customerId);
clientNotFoundMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(clientNotFoundMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
customer = LinkedInCustomerResource.getCustomerList().get(customerId);
client = customer.getClientDB().getClientList().get(clientId);
if (client.getStatus() == linkStatusOff) {
notLinkedMsg = new NotLinked();
notLinkedMsg.setCustomerId(customerId);
notLinkedMsg.setClientId(clientId);
return Response.status(Response.Status.OK).entity(notLinkedMsg).type(MediaType.APPLICATION_JSON_TYPE).build();
}
JsonParser jsonParser = new JsonParser();
JSONObject positionJsonObj;
JSONArray positionsValuesArr;
JSONObject positionValuesJsonObj;
JSONObject companyJsonObj;
JSONObject startDateJsonObj;
// get response body
OAuthRequest request = new OAuthRequest(Verb.GET, LinkedInAppResource.API_DETAILED_PROFILE_URI);
request.addHeader("x-li-format", "json");
OAuthService service = client.getLinkHandler().getServiceProvider();
service.signRequest(client.getLinkHandler().getAccessToken(), request);
org.scribe.model.Response response = request.send();
// get Json Objects and Array from response
JSONObject detailedProfileJsonObj = new JSONObject(response.getBody());
positionJsonObj = detailedProfileJsonObj.getJSONObject("positions");
if (positionJsonObj.isNull("values")) {
positionsValuesArr = null;
jsonParser.parseDetailedWithoutPositionIsNull();
} else {
positionsValuesArr = positionJsonObj.getJSONArray("values");
positionValuesJsonObj = positionsValuesArr.getJSONObject(0);
companyJsonObj = positionValuesJsonObj.getJSONObject("company");
startDateJsonObj = positionValuesJsonObj.getJSONObject("startDate");
// store the values to object
jsonParser.parseJsonOfDetailedProfile(detailedProfileJsonObj, positionJsonObj, positionValuesJsonObj, companyJsonObj,
startDateJsonObj);
}
client.setProfile(jsonParser.getProfile());
return Response.status(Response.Status.OK).entity(client.getProfile()).type(MediaType.APPLICATION_JSON_TYPE).build();
}