本文整理汇总了Java中com.github.scribejava.core.model.Token类的典型用法代码示例。如果您正苦于以下问题:Java Token类的具体用法?Java Token怎么用?Java Token使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Token类属于com.github.scribejava.core.model包,在下文中一共展示了Token类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: loadOAuthProviderAccount
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {
//example of rawResponse:
//{"access_token":"####-#####-#####-####","token_type":"bearer","refresh_token":"####-#####-#####-####",
//"expires_in":631138518,"scope":"/authenticate","name":"Karen L. Hanson","orcid":"0000-0002-9354-8328"}
String jsonString = accessToken.getRawResponse();
LOG.debug("Raw response: {}", jsonString);
JSONObject root = new JSONObject(jsonString);
String displayName = root.getString("name");
String accountId = root.getString("orcid");
String publicId = provider.getIdProviderUrl() + "/" + accountId;
String profilePath = publicId;
OAuthProviderAccount profile =
new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
return profile;
}
开发者ID:rmap-project,项目名称:rmap,代码行数:19,代码来源:OrcidOAuthProvider.java
示例2: loadOAuthProviderAccount
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:rmap-project,项目名称:rmap,代码行数:23,代码来源:TwitterOAuthProvider.java
示例3: logintwitter
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* Login using Twitter.
*
* @param session the HTTP session
* @return the welcome page
*/
@RequestMapping(value={"/user/login/twitter"}, method = RequestMethod.GET)
public String logintwitter(HttpSession session) {
if (!siteProperties.isTwitterEnabled()) {
LOG.debug("Twitter OAuth unavailable, redirecting to home page");
return "redirect:/home";
}
//see if we are already logged in
OAuthProviderAccount account = (OAuthProviderAccount) session.getAttribute("account");
if(account == null) {
Token requestToken = oAuthProviderTwitter.createRequestToken();
session.setAttribute("requesttoken", requestToken);
//not logged in create service and redirect to twitter login
return "redirect:" + oAuthProviderTwitter.getAuthorizationUrl(requestToken);
}
//already logged in goto welcome page
return "redirect:/user/welcome";
}
开发者ID:rmap-project,项目名称:rmap,代码行数:24,代码来源:LoginController.java
示例4: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:26,代码来源:ParseAccountData.java
示例5: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseStockQuote.java
示例6: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:24,代码来源:ParseOptionStrikePrice.java
示例7: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseOptionOrder.java
示例8: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的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;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:26,代码来源:ParseOptionOrderPreview.java
示例9: DefaultJsonConverter
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
public DefaultJsonConverter() {
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.IS_GETTER, JsonAutoDetect.Visibility.NONE);
mapper.addMixIn(OAuth1RequestToken.class, OAuth1RequestTokenMixin.class)
.addMixIn(BearerAccessToken.class, BearerAccessTokenMixin.class)
.addMixIn(Scope.Value.class, ValueMixin.class)
.addMixIn(Token.class, TokenMixin.class);
}
开发者ID:millross,项目名称:pac4j-async,代码行数:11,代码来源:DefaultJsonConverter.java
示例10: loadOAuthProviderAccount
import com.github.scribejava.core.model.Token; //导入依赖的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);
Response oauthResponse = oauthRequest.send();
String jsonString = oauthResponse.getBody();
JSONObject root = new JSONObject(jsonString);
JSONArray emailArray = root.getJSONArray(GOOGLE_JSON_EMAILLIST_PROPERTY);
JSONObject firstEmail = emailArray.getJSONObject(0);
String accountId = root.getString(GOOGLE_JSON_ACCOUNTID_PROPERTY);
String displayName = root.getString(GOOGLE_JSON_DISPLAYNAME_PROPERTY);
String publicId = firstEmail.getString(GOOGLE_JSON_EMAIL_PROPERTY);
String profilePath="";
if (root.has(GOOGLE_JSON_PROFILEPATH_PROPERTY)){
profilePath = root.getString(GOOGLE_JSON_PROFILEPATH_PROPERTY);
}
OAuthProviderAccount profile =
new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
return profile;
}
开发者ID:rmap-project,项目名称:rmap,代码行数:28,代码来源:GoogleOAuthProvider.java
示例11: OAuthProviderAccount
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* Instantiates a new OAuth provider account.
*
* @param accessToken the access token
* @param providerName the provider name
* @param displayName the display name
* @param accountId the account id
* @param accountPublicId the account public id
* @param profilePath the profile path
*/
public OAuthProviderAccount(Token accessToken, OAuthProviderName providerName,
String displayName, String accountId,
String accountPublicId, String profilePath) {
this.setAccessToken(accessToken);
this.setProviderName(providerName);
this.setDisplayName(displayName);
this.setAccountId(accountId);
this.setAccountPublicId(accountPublicId);
this.setProfilePath(profilePath);
}
开发者ID:rmap-project,项目名称:rmap,代码行数:21,代码来源:OAuthProviderAccount.java
示例12: createAccessToken
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* Creates an access token.
*
* @param requestToken the request token
* @param oauthVerifier the OAuth verifier
* @return the access token
*/
//for oauth2 requestToken is null
public Token createAccessToken(Token requestToken,String oauthVerifier) {
// create access token
Verifier verifier = new Verifier(oauthVerifier);
Token accessToken = this.getService().getAccessToken(requestToken, verifier);
return accessToken;
}
开发者ID:rmap-project,项目名称:rmap,代码行数:15,代码来源:OAuthProvider.java
示例13: googlecallback
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* Googlecallback.
*
* @param oauthVerifier the oauth verifier
* @param session the HTTP session
* @param model the Spring model
* @return the signup or welcome page depending on whether account exists.
*/
@RequestMapping(value={"/user/googlecallback"}, method = RequestMethod.GET)
public String googlecallback(@RequestParam(value="code", required=false) String oauthVerifier, HttpSession session, Model model) {
if (!siteProperties.isGoogleEnabled()) {
LOG.debug("Google OAuth unavailable, redirecting to home page");
return "redirect:/home";
}
Token accessToken = oAuthProviderGoogle.createAccessToken(null, oauthVerifier);
//load profile from request to service
OAuthProviderAccount account =
oAuthProviderGoogle.loadOAuthProviderAccount(accessToken, OAuthProviderName.GOOGLE);
// store access token as a session attribute
session.setAttribute("account", account);
User user = userMgtService.loadUserFromOAuthAccount(account);
if (user==null){
String name = account.getDisplayName();
String email = account.getAccountPublicId();
session.setAttribute("user", new User(name, email));
return "redirect:/user/signup";
}
else {
session.setAttribute("user", user);
return "redirect:/user/welcome";
}
}
开发者ID:rmap-project,项目名称:rmap,代码行数:38,代码来源:LoginController.java
示例14: orcidcallback
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* ORCID callback page.
*
* @param oauthVerifier the oauth verifier
* @param session the HTTP session
* @param model the Spring model
* @return the signup or welcome page depending on whether account exists.
*/
@RequestMapping(value={"/user/orcidcallback"}, method = RequestMethod.GET)
public String orcidcallback(@RequestParam(value="code", required=false) String oauthVerifier,
@RequestParam(value="error", required=false) String error, @RequestParam(value="error_description", required=false) String errorDescription,
RedirectAttributes redirectAttributes, HttpSession session, Model model) {
if (!siteProperties.isOrcidEnabled()) {
LOG.debug("ORCID OAuth unavailable, redirecting to home page");
return "redirect:/home";
}
if (error!=null && error.equals("access_denied")){
redirectAttributes.addFlashAttribute("notice", "The ORCID Login failed with the following error:" + errorDescription);
return "redirect:/user/login";
}
Token accessToken = oAuthProviderOrcid.createAccessToken(null, oauthVerifier);
//load profile from request to service
OAuthProviderAccount account =
oAuthProviderOrcid.loadOAuthProviderAccount(accessToken, OAuthProviderName.ORCID);
// store account as a session attribute
session.setAttribute("account", account);
User user = userMgtService.loadUserFromOAuthAccount(account);
if (user==null){
session.setAttribute("user", new User(account.getDisplayName()));
return "redirect:/user/signup";
}
else {
session.setAttribute("user", user);
return "redirect:/user/welcome";
}
}
开发者ID:rmap-project,项目名称:rmap,代码行数:40,代码来源:LoginController.java
示例15: twittercallback
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
/**
* Twitter callback.
*
* @param oauthToken the oauth token
* @param oauthVerifier the oauth verifier
* @param session the HTTP session
* @param model the Spring model
* @return the signup or welcome page depending on whether account exists.
*/
@RequestMapping(value={"/user/twittercallback"}, method = RequestMethod.GET)
public String twittercallback(@RequestParam(value="oauth_token", required=false) String oauthToken,
@RequestParam(value="oauth_verifier", required=false) String oauthVerifier, HttpSession session, Model model) {
if (!siteProperties.isTwitterEnabled()) {
LOG.debug("Twitter OAuth unavailable, redirecting to home page");
return "redirect:/home";
}
Token requestToken = (Token) session.getAttribute("requesttoken");
if (requestToken == null){
return "redirect:/user/login";
}
Token accessToken =
oAuthProviderTwitter.createAccessToken(requestToken,oauthVerifier);
//load profile from request to service
OAuthProviderAccount account =
oAuthProviderTwitter.loadOAuthProviderAccount(accessToken, OAuthProviderName.TWITTER);
// store access token as a session attribute
session.setAttribute("account", account);
User user = userMgtService.loadUserFromOAuthAccount(account);
if (user==null){
session.setAttribute("user", new User(account.getDisplayName()));
return "redirect:/user/signup";
}
else {
session.setAttribute("user", user);
return "redirect:/user/welcome";
}
}
开发者ID:rmap-project,项目名称:rmap,代码行数:44,代码来源:LoginController.java
示例16: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
protected MarketDay doInBackground(Void... arg0){
//not sure if this is right if the assignment below will happen correctly.
MarketDay marketDay = new MarketDay();
//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.getMarketYesterdaysMinuteData(symbol), service);
service.signRequest(accessToken, request);
Response response = request.send();
//try parsing the JSON data.
try {
marketDay = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
marketDay.setError(e.toString());
}
return marketDay;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:28,代码来源:ParseData.java
示例17: doInBackground
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
protected OpenOptionPosition doInBackground(Void... voids){
//sleep for a second for rate limiting.
SystemClock.sleep(1000);
OpenOptionPosition openOptionPosition = new OpenOptionPosition();
//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.getOpenOptionPositions(), service);
service.signRequest(accessToken, request);
Response response = request.send();
try {
openOptionPosition = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
openOptionPosition.setError(e.toString());
}
return openOptionPosition;
}
开发者ID:mikemey01,项目名称:Markets,代码行数:28,代码来源:ParseOpenPosition.java
示例18: callback
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
@Override
public void callback(CallbackContext context) {
HttpServletRequest request = context.getRequest();
OAuthService scribe = prepareScribe(context).build();
String oAuthVerifier = request.getParameter("code");
Token accessToken = scribe.getAccessToken(EMPTY_TOKEN, new Verifier(oAuthVerifier));
OAuthRequest userRequest = new OAuthRequest(Verb.GET, gitLabConfiguration.url() + "/api/" + gitLabConfiguration.apiVersion() + "/user", scribe);
scribe.signRequest(accessToken, userRequest);
com.github.scribejava.core.model.Response userResponse = userRequest.send();
if (!userResponse.isSuccessful()) {
throw new IllegalStateException(format("Fail to authenticate the user. Error code is %s, Body of the response is %s", userResponse.getCode(), userResponse.getBody()));
}
String userResponseBody = userResponse.getBody();
LOGGER.trace("User response received : %s", userResponseBody);
GsonUser gsonUser = GsonUser.parse(userResponseBody);
UserIdentity.Builder builder = UserIdentity.builder().setProviderLogin(gsonUser.getUsername()).setLogin(gsonUser.getUsername()).setName(gsonUser.getName()).setEmail(gsonUser.getEmail());
if (!gitLabConfiguration.userExceptions().contains(gsonUser.getUsername())) {
Set<String> groups = getUserGroups(accessToken);
if (!groups.isEmpty()) {
builder.setGroups(groups);
}
}
context.authenticate(builder.build());
context.redirectToRequestedPage();
}
开发者ID:gabrie-allaigre,项目名称:sonar-auth-gitlab-plugin,代码行数:31,代码来源:GitLabIdentityProvider.java
示例19: getUserGroups
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
private Set<String> getUserGroups(Token accessToken) {
Set<String> groups = new HashSet<>();
if (!gitLabConfiguration.groups().isEmpty()) {
groups.addAll(gitLabConfiguration.groups());
}
if (gitLabConfiguration.syncUserGroups()) {
groups.addAll(getUserGitLabGroups(accessToken));
}
return groups;
}
开发者ID:gabrie-allaigre,项目名称:sonar-auth-gitlab-plugin,代码行数:11,代码来源:GitLabIdentityProvider.java
示例20: main
import com.github.scribejava.core.model.Token; //导入依赖的package包/类
public static void main(String[] args) {
// Replace these with your client id and secret
final String clientId = "your client id";
final String clientSecret = "your client secret";
final OAuthService service = new ServiceBuilder()
.provider(StravaOAuth2Api.class)
.apiKey(clientId)
.apiSecret(clientSecret)
.callback("http://localhost:8080/oauth/callback")
.build();
final Scanner in = new Scanner(System.in, "UTF-8");
// Obtain the Authorization URL
final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
System.out.println("Go to authorization URL:");
System.out.println(authorizationUrl);
System.out.println("Copy/paste the authorization code here");
System.out.print(">>");
final Verifier verifier = new Verifier(in.nextLine());
System.out.println();
System.out.println("Trading the Request Token for an Access Token...");
final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken + " )");
}
开发者ID:tiberiu-biking,项目名称:scribejava-strava,代码行数:31,代码来源:StravaOAuth2ApiTest.java
注:本文中的com.github.scribejava.core.model.Token类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论