本文整理汇总了Java中com.github.scribejava.core.model.Verb类的典型用法代码示例。如果您正苦于以下问题:Java Verb类的具体用法?Java Verb怎么用?Java Verb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Verb类属于com.github.scribejava.core.model包,在下文中一共展示了Verb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureOAuth20Client
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
private void configureOAuth20Client(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getOauth2()
.stream()
.filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret()))
.forEach(oauth -> {
final GenericOAuth20Client client = new GenericOAuth20Client();
client.setKey(oauth.getId());
client.setSecret(oauth.getSecret());
client.setProfileAttrs(oauth.getProfileAttrs());
client.setProfileNodePath(oauth.getProfilePath());
client.setProfileUrl(oauth.getProfileUrl());
client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
client.setTokenUrl(oauth.getTokenUrl());
client.setAuthUrl(oauth.getAuthUrl());
client.setCustomParams(oauth.getCustomParams());
final int count = index.intValue();
if (count > 0) {
client.setName(client.getClass().getSimpleName() + count);
}
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
示例2: main
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
public static void main (String[] args) {
ResourceBundle secrets = ResourceBundle.getBundle("facebookutil/secret");
final OAuth20Service service = new ServiceBuilder()
.apiKey(secrets.getString("clientId"))
.apiSecret(secrets.getString("clientSecret"))
.callback("https://duke.edu/")
.grantType("client_credentials")
.build(FacebookApi.instance());
String url = "https://graph.facebook.com/oauth/access_token?";
url = url + "&client_id" + "=" + secrets.getString("clientId");
url = url + "&client_secret" + "=" + secrets.getString("clientSecret");
url = url + "&grant_type" + "=" + "client_credentials";
final OAuthRequest request =
new OAuthRequest(Verb.GET, url, service);
service.signRequest(new OAuth2AccessToken(""), request);
System.out.println(request.getBodyContents());
System.out.println(request.getUrl());
Response response = request.send();
System.out.println(response.getBody());
}
示例3: validate
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
if (credential instanceof TokenResponseCredential) {
TokenResponseCredential tokenCredential = (TokenResponseCredential) credential;
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/userinfo");
OAuth20Service service = tokenCredential.getService();
OAuth2AccessToken token = tokenCredential.getTokenResponse();
service.signRequest(token, request);
try {
Response oResp = service.execute(request);
String body = oResp.getBody();
OAuth2User oAuth2User = jsonProcessor.extractUserInfo(body);
return new CredentialValidationResult(oAuth2User);
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace(); // FIXME
}
}
return CredentialValidationResult.NOT_VALIDATED_RESULT;
}
示例4: sendRequestForData
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
/**
* Make a request to get the data of the authenticated user for the provider.
*
* @param accessToken the access token
* @param dataUrl url of the data
* @param verb method used to request data
* @return the user data response
*/
protected CompletableFuture<String> sendRequestForData(final T accessToken, final String dataUrl, Verb verb) {
logger.debug("accessToken: {} / dataUrl: {}", accessToken, dataUrl);
final long t0 = System.currentTimeMillis();
final OAuthRequestAsync request = createOAuthRequest(dataUrl, verb);
signRequest(accessToken, request);
final CompletableFuture<Response> responseFuture = new CompletableFuture<>();
request.sendAsync(ScribeCallbackAdapter.toScribeOAuthRequestCallback(responseFuture));
return responseFuture.thenApply(response -> {
final int code = response.getCode();
final String body;
try {
body = response.getBody();
} catch (final IOException ex) {
throw new HttpCommunicationException("Error getting body: " + ex.getMessage());
}
final long t1 = System.currentTimeMillis();
logger.debug("Request took: " + (t1 - t0) + " ms for: " + dataUrl);
logger.debug("response code: {} / response body: {}", code, body);
if (code != 200) {
throw new HttpCommunicationException(code, body);
}
return body;
});
}
示例5: loadOAuthProviderAccount
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {
OAuthService service = this.getService();
// getting user profile
OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);
service.signRequest(accessToken, oauthRequest); // the access token from step 4
Response oauthResponse = oauthRequest.send();
String jsonString = oauthResponse.getBody();
JSONObject root = new JSONObject(jsonString);
String accountId = String.valueOf(root.getInt(TWITTER_ACCTID_PROPERTY));
String displayName = root.getString(TWITTER_DISPLAYNAME_PROPERTY);
String publicId = root.getString(TWITTER_SCREENNAME_PROPERTY);
String profilePath = provider.getIdProviderUrl() + "/" + publicId;
OAuthProviderAccount profile =
new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
return profile;
}
示例6: doInBackground
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
protected AccountData doInBackground(Void... voids) {
AccountData aData = new AccountData();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getFullAccountInfo(), service);
service.signRequest(accessToken, request);
Response response = request.send();
//parse json
try {
aData = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
aData.setError(e.toString());
}
return aData;
}
示例7: doInBackground
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
protected StockQuote doInBackground(Void... voids){
//pause for a second so we don't get rate limited
SystemClock.sleep(1000);
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getMarketQuote(symbol), service);
service.signRequest(accessToken, request);
Response response = request.send();
StockQuote quote = new StockQuote(symbol);
try {
quote = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
quote.setError(e.toString());
}
return quote;
}
示例8: doInBackground
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
protected Double doInBackground(Void... voids){
double ret = 0.0;
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getOptionStrikePrices(symbol), service);
service.signRequest(accessToken, request);
Response response = request.send();
try {
ret = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
}
return ret;
}
示例9: doInBackground
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
protected OptionOrder doInBackground(Void... voids){
OptionOrder order = new OptionOrder();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.POST, tk.getMarketOptionLive(), service);
//request.addHeader("TKI_OVERRIDE", "true");
request.addPayload(fixml.getLimitFixmlString());
service.signRequest(accessToken, request);
Response response = request.send();
try {
order = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
order.setError(e.toString());
}
return order;
}
示例10: doInBackground
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
protected OptionOrderPreview doInBackground(Void... voids){
OptionOrderPreview order = new OptionOrderPreview();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.POST, tk.getMarketOptionPreview(), service);
request.addPayload(fixml.getMarketFixmlString());
service.signRequest(accessToken, request);
Response response = request.send();
try {
order = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
order.setError(e.toString());
}
return order;
}
示例11: processRequest
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
private void processRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String code = req.getParameter("code");
LOGGER.info("OAuth2 code: [{}]", code);
String provider = StringUtils.substringAfterLast(req.getRequestURI(), "/");
LOGGER.info("Provider: [{}]", provider);
OAuth20Service oAuth2Service = this.providerFactory.getOAuth2Service(provider);
OAuth2AccessToken token = null;
try {
token = oAuth2Service.getAccessToken(code);
LOGGER.info("OAuth2AccessToken: [{}]", token);
OAuthRequest oReq = new OAuthRequest(Verb.GET, "https://api.linkedin.com/v1/people/~?format=json");
oAuth2Service.signRequest(token, oReq);
Response oResp = oAuth2Service.execute(oReq);
LOGGER.info("Linkedin Profile: [{}]", oResp.getBody());
resp.getOutputStream().write(oResp.getBody().getBytes(StandardCharsets.UTF_8));
} catch (InterruptedException | ExecutionException ex) {
}
}
示例12: verfiyAccountCredentials
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
/**
* Verify account credentials against the Twitter API
*/
private void verfiyAccountCredentials() throws TwitterException {
OAuthRequest verifyRequest = createOAuthRequest(Verb.GET, VERIFY_CREDENTIALS_URL);
signRequest(verifyRequest);
try {
Response response = service.execute(verifyRequest);
if (response.getMessage().toLowerCase().equals("Too Many Requests")) {
throw new TwitterException("Too many requests for this account.");
} else if (!response.getMessage().toLowerCase().equals("ok")) {
throw new TwitterException("Invalid twitter configuration");
}
} catch (IOException | ExecutionException | InterruptedException e) {
throw new TwitterException("Could not verify account credentials.");
}
}
示例13: getRequestForProvider
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
static public OAuthRequest getRequestForProvider(
final String providerName,
final Verb httpVerb,
final OAuth1AccessToken oa1token,
final URL url,
final HashMap<String,Object> cfg,
@Nullable final ReadableMap params
) {
final OAuth10aService service =
OAuthManagerProviders.getApiFor10aProvider(providerName, cfg, null, null);
String token = oa1token.getToken();
OAuthConfig config = service.getConfig();
OAuthRequest request = new OAuthRequest(httpVerb, url.toString(), config);
request = OAuthManagerProviders.addParametersToRequest(request, token, params);
// Nothing special for Twitter
return request;
}
示例14: isOrganizationMember
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
/**
* Check to see that login is a member of organization.
*
* A 204 response code indicates organization membership. 302 and 404 codes are not treated as exceptional,
* they indicate various ways in which a login is not a member of the organization.
*
* @see <a href="https://developer.github.com/v3/orgs/members/#response-if-requester-is-an-organization-member-and-user-is-a-member">GitHub members API</a>
*/
private boolean isOrganizationMember(OAuth2AccessToken accessToken, String organization, String login) throws IOException, ExecutionException, InterruptedException {
String requestUrl = settings.apiURL() + format("orgs/%s/members/%s", organization, login);
OAuth20Service scribe = new ServiceBuilder(settings.clientId())
.apiSecret(settings.clientSecret())
.build(scribeApi);
OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl);
scribe.signRequest(accessToken, request);
Response response = scribe.execute(request);
int code = response.getCode();
switch (code) {
case HttpURLConnection.HTTP_MOVED_TEMP:
case HttpURLConnection.HTTP_NOT_FOUND:
case HttpURLConnection.HTTP_NO_CONTENT:
LOGGER.trace("Orgs response received : {}", code);
return code == HttpURLConnection.HTTP_NO_CONTENT;
default:
throw unexpectedResponseCode(requestUrl, response);
}
}
示例15: getSingleUseToken
import com.github.scribejava.core.model.Verb; //导入依赖的package包/类
public String getSingleUseToken() {
OAuth10aService service = JamAuthConfig.instance().getOAuth10aService();
final OAuthRequest request = new OAuthRequest(Verb.POST,
JamAuthConfig.instance().getServerUrl() + "/v1/single_use_tokens",
service);
service.signRequest(JamAuthConfig.instance().getOAuth10aAccessToken(), request);
final Response response = request.send();
String body = response.getBody();
Matcher matcher = SINGLE_USE_TOKEN_PATTERN.matcher(body);
if (matcher.find()) {
return matcher.group(0);
}
return null;
}