当前位置: 首页>>代码示例>>Java>>正文


Java OAuth2AccessToken类代码示例

本文整理汇总了Java中com.github.scribejava.core.model.OAuth2AccessToken的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AccessToken类的具体用法?Java OAuth2AccessToken怎么用?Java OAuth2AccessToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OAuth2AccessToken类属于com.github.scribejava.core.model包,在下文中一共展示了OAuth2AccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的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());
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:21,代码来源:TestAppLogin.java

示例2: validate

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的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;
}
 
开发者ID:atbashEE,项目名称:jsr375-extensions,代码行数:27,代码来源:DemoIdentityStore.java

示例3: getProfileUrl

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
@Override
protected String getProfileUrl(OAuth2AccessToken accessToken) {
    String baseParams =
            "application_key=" + publicKey +
                    "&format=json" +
                    "&method=users.getCurrentUser";
    String finalSign;
    try {
        String preSign = getMD5SignAsHexString(accessToken.getAccessToken() + getSecret());
        finalSign = getMD5SignAsHexString(baseParams.replaceAll("&", "") + preSign);
    } catch (Exception e) {
        logger.error(e.getMessage());
        return null;
    }
    return API_BASE_URL + baseParams + "&access_token=" + accessToken.getAccessToken() + "&sig=" + finalSign;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:17,代码来源:OkClient.java

示例4: extract

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
@Override
public OAuth2AccessToken extract(String response) {

    String errorCode = RegexUtil.extractParameter(response, ERRORCODE_REGEX);
    if (errorCode != null) {
        String errorDesc = RegexUtil.extractParameter(response, ERRORDESC_REGEX);
        if (errorDesc != null) {
            errorDesc = errorDesc.replace("+", " ");
        }
        return new GatewayAccessToken(errorCode, errorDesc, response);
    }

    OAuth2AccessToken accessToken = super.extract(response);
    return new GatewayAccessToken(accessToken.getAccessToken(), accessToken.getTokenType()
            , null, null, accessToken.getScope(), response);
}
 
开发者ID:perrywang,项目名称:OAuthGateway,代码行数:17,代码来源:GitHubOAuth2AccessTokenExtractor.java

示例5: extract

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public OAuth2AccessToken extract(String response) {
    String accessToken = null;
    String tokenType= null;
    Integer expiresIn = null;
    String refreshToken = null;
    String scope = null;

    Preconditions.checkEmptyString(response,
            "Response body is incorrect. Can't extract a token from an empty string");
    try {
        JsonNode actualObj = mapper.readTree(response);
        accessToken = actualObj.get("access_token").asText();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new OAuth2AccessToken(accessToken, tokenType, expiresIn, refreshToken, scope, response);
}
 
开发者ID:danielyinanc,项目名称:instagram-oauth2,代码行数:22,代码来源:InstagramOAuth2TokenExtractor.java

示例6: processRequest

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的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) {
	}
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:19,代码来源:OAuth2CallbackServlet.java

示例7: getRequestForProvider

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
static public OAuthRequest getRequestForProvider(
  final String providerName,
  final Verb httpVerb,
  final OAuth2AccessToken oa2token,
  final URL url,
  final HashMap<String,Object> cfg,
  @Nullable final ReadableMap params
) {
  final OAuth20Service service =
      OAuthManagerProviders.getApiFor20Provider(providerName, cfg, null, null);

  OAuthConfig config = service.getConfig();
  OAuthRequest request = new OAuthRequest(httpVerb, url.toString(), config);
  String token = oa2token.getAccessToken();

  request = OAuthManagerProviders.addParametersToRequest(request, token, params);

  //
  Log.d(TAG, "Making request for " + providerName + " to add token " + token);
  // Need a way to standardize this, but for now
  if (providerName.equalsIgnoreCase("slack")) {
    request.addParameter("token", token);
  }

  return request;
}
 
开发者ID:fullstackreact,项目名称:react-native-oauth,代码行数:27,代码来源:OAuthManagerProviders.java

示例8: isOrganizationMember

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的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);
  }
}
 
开发者ID:SonarSource,项目名称:sonar-auth-github,代码行数:29,代码来源:GitHubIdentityProvider.java

示例9: getOptions

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
public Future<EveData> getOptions(CrestRequestData requestData, ClientElement client)
{
    String accessToken = null;
    if (requestData.clientInfo != null)
        accessToken = ((OAuth2AccessToken) requestData.clientInfo.getAccessToken()).getAccessToken();
    HttpOptions get = new HttpOptions(requestData.url);
    if (accessToken != null)
    {
        get.addHeader("Authorization", "Bearer " + accessToken);
        if (requestData.scope != null)
            get.addHeader("Scope", requestData.scope);
    }
    if (requestData.version != null)
        get.addHeader("Accept", requestData.version);
    return executor.submit(new CrestGetTask(client, get, requestData));
}
 
开发者ID:timpanogos,项目名称:crestj,代码行数:17,代码来源:CrestClient.java

示例10: processResponse

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
private void processResponse (Response response,
                              ResourceBundle secrets,
                              OAuth20Service service) {
    LoginObject login = new LoginObject();
    login.setUserID(secrets.getString("facebookId"));
    login.setToken(new OAuth2AccessToken(ParseHelper.getFirstGroup(TOKEN_REGEX,
                                                                   response.getBody())));
    login.setService(service);
    myLoginObject = login;
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:11,代码来源:FacebookAppLogin.java

示例11: checkForLogin

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
/**
 * Checks if url matches the code regex, then logs in if successful
 *
 * @param newURL
 */
private void checkForLogin (String newURL) {
    Matcher m = Pattern.compile(CODE_REGEX).matcher(newURL);
    if (m.find()) {
        OAuth2AccessToken token = myLoginObject.getService().getAccessToken(m.group(1));
        myLoginObject.setToken(token);
        findProfile();
        login();
    }
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:15,代码来源:FacebookListener.java

示例12: doInBackground

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
protected OAuth2AccessToken doInBackground(String... code) {
    try {
        return service.getAccessToken(code[0]);
    } catch (IOException e) {
        e.printStackTrace();
        setStatusMessage("Failed to exchange code for a token.");
        enableRetryButton();
    }
    return null;
}
 
开发者ID:jpmeijers,项目名称:ttnmapper_android_v2,代码行数:11,代码来源:LogInToTTN.java

示例13: onPostExecute

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
protected void onPostExecute(OAuth2AccessToken result) {
    if(result!=null)
    {
        accessToken = result;
        new getApplications().execute("");
        setStatusMessage("Token received");
    }

}
 
开发者ID:jpmeijers,项目名称:ttnmapper_android_v2,代码行数:10,代码来源:LogInToTTN.java

示例14: signRequest

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
@Override
protected void signRequest(OAuth2AccessToken token, OAuthRequestAsync request) {
    this.configuration.getService().signRequest(token, request);
    if (this.configuration.isTokenAsHeader()) {
        request.addHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + token.getAccessToken());
    }
    if (Verb.POST.equals(request.getVerb())) {
        request.addParameter(OAuthConfiguration.OAUTH_TOKEN, token.getAccessToken());
    }
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:11,代码来源:AsyncOAuth20ProfileCreator.java

示例15: addAccessTokenToProfile

import com.github.scribejava.core.model.OAuth2AccessToken; //导入依赖的package包/类
@Override
protected void addAccessTokenToProfile(U profile, OAuth2AccessToken accessToken) {
    if (profile != null) {
        final String token = accessToken.getAccessToken();
        logger.debug("add access_token: {} to profile", token);
        profile.setAccessToken(token);
    }
}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:9,代码来源:AsyncOAuth20ProfileCreator.java


注:本文中的com.github.scribejava.core.model.OAuth2AccessToken类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。