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


Java OAuth20Service类代码示例

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


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

示例1: main

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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: getAuthURL

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
/**
 * @return A string containing a URL that we can send visitors to in order to authenticate them
 */
public String getAuthURL(String originatingURL){
    // I think we have to create a new service for every request we send out
    // since each one needs a different secretState
    final OAuth20Service service = new ServiceBuilder()
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .scope("email") // replace with desired scope
            .state(generateSharedGoogleSecret(originatingURL))
            .callback(callbackURL)
            .build(GoogleApi20.instance());

    final Map<String, String> additionalParams = new HashMap<>();
    additionalParams.put("access_type", "offline");
    additionalParams.put("prompt", "consent");
    final String authorizationUrl = service.getAuthorizationUrl(additionalParams);

    return authorizationUrl;
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:22,代码来源:Auth.java

示例3: validate

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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

示例4: redirect

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@Override
public CompletableFuture<RedirectAction> redirect(AsyncWebContext context) {
    init(context);

    final CompletableFuture<OAuth20Service> serviceFuture;

    if (this.configuration.isWithState()) {
        final String state = getStateParameter();
        logger.debug("save sessionState: {}", state);
        serviceFuture = context.getSessionStore().set(context, this.configuration.getStateSessionAttributeName(), state)
            .thenApply(v -> this.configuration.buildService(context, state));
    } else {
        serviceFuture = CompletableFuture.completedFuture(this.configuration.getService());
    }

    return serviceFuture.thenApply(service -> service.getAuthorizationUrl(this.configuration.getCustomParams()))
            .thenApply(authUrl -> {
                logger.debug("authorizationUrl: {}", authUrl);
                return RedirectAction.redirect((String) authUrl);
            });


}
 
开发者ID:millross,项目名称:pac4j-async,代码行数:24,代码来源:AsyncOauth20RedirectActionBuilder.java

示例5: doGet

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String providerName = StringUtils.substringAfterLast(req.getRequestURI(), "/");
	LOGGER.info("Authz request for provider: [{}]", providerName);
	OAuthProvider provider = this.providerFactory.getProvider(providerName);
	LOGGER.info("OAuthProvider: [{}]", provider);
	OAuth20Service oauth2Service = this.providerFactory.getOAuth2Service(providerName);
	if (oauth2Service == null) {
		oauth2Service = new ServiceBuilder().apiKey(provider.getApiKey()).apiSecret(provider.getApiSecret())
				.callback(provider.getCallbackURL()).build(provider.getApi());
		this.providerFactory.addOAuth2Service(providerName, oauth2Service);
	}
	String authorizationUrl = oauth2Service.getAuthorizationUrl();
	LOGGER.info("Authz URL: [{}]", authorizationUrl);
	resp.sendRedirect(authorizationUrl);
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:17,代码来源:OAuth2AuthorizationRequestServlet.java

示例6: processRequest

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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: login

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
@RequestMapping("/login")
public OAuthResponse login()
{
	UUID uuid = UUID.randomUUID();

	State state = new State();
	state.setUuid(uuid);
	state.setApiVersion(RuneLiteAPI.getVersion());

	OAuth20Service service = new ServiceBuilder()
		.apiKey(oauthClientId)
		.apiSecret(oauthClientSecret)
		.scope(SCOPE)
		.callback(RL_OAUTH_URL)
		.state(gson.toJson(state))
		.build(GoogleApi20.instance());

	String authorizationUrl = service.getAuthorizationUrl();

	OAuthResponse lr = new OAuthResponse();
	lr.setOauthUrl(authorizationUrl);
	lr.setUid(uuid);

	return lr;
}
 
开发者ID:runelite,项目名称:runelite,代码行数:26,代码来源:AccountService.java

示例8: getRequestForProvider

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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

示例9: configurableService

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private static OAuth20Service configurableService(
  final HashMap cfg,
  @Nullable final ReadableMap opts,
  final String callbackUrl
) {
  ServiceBuilder builder = OAuthManagerProviders._oauth2ServiceBuilder(cfg, opts, callbackUrl);
  Log.d(TAG, "Creating ConfigurableApi");
  //Log.d(TAG, "    authorize_url:     " + cfg.get("authorize_url"));
  //Log.d(TAG, "    access_token_url:  " + cfg.get("access_token_url"));
  ConfigurableApi api = ConfigurableApi.instance()
    .setAccessTokenEndpoint((String) cfg.get("access_token_url"))
    .setAuthorizationBaseUrl((String) cfg.get("authorize_url"));
  if (cfg.containsKey("access_token_verb")) {
    //Log.d(TAG, "    access_token_verb: " + cfg.get("access_token_verb"));
    api.setAccessTokenVerb((String) cfg.get("access_token_verb"));
  }

  return builder.build(api);
}
 
开发者ID:fullstackreact,项目名称:react-native-oauth,代码行数:20,代码来源:OAuthManagerProviders.java

示例10: OAuthManagerFragmentController

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public OAuthManagerFragmentController(
  final ReactContext mReactContext,
  android.app.FragmentManager fragmentManager,
  final String providerName,
  OAuth20Service oauthService,
  final String callbackUrl
) {
  this.uiHandler = new Handler(Looper.getMainLooper());
  this.fragmentManager = fragmentManager;

  this.context = mReactContext;
  this.providerName = providerName;
  this.authVersion = "2.0";
  this.oauth20Service = oauthService;
  this.callbackUrl = callbackUrl;
}
 
开发者ID:fullstackreact,项目名称:react-native-oauth,代码行数:17,代码来源:OAuthManagerFragmentController.java

示例11: googleLogin

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public void googleLogin() throws IOException {
    String CALL_BACK_URL="http://localhost:8084/loginAndSec/GcallBack";
    ExternalContext externalContext = externalContext();
    HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
   
    String callBackURL = CALL_BACK_URL; 
    //System.out.println("google.GoogleLoginServlet.doGet(): callBackURL=" + callBackURL);
    //Configure
    ServiceBuilder builder = new ServiceBuilder();
    OAuth20Service service = builder.apiKey(CLIENT_ID)
            .apiSecret(CLIENT_SECRET)
            .callback(callBackURL)
            .scope("email")
            .build(GoogleApi20.instance()); //Now build the call

    HttpSession sess = request.getSession();
    sess.setAttribute("oauth2Service", service);
    String authURL = service.getAuthorizationUrl(null);
    //System.out.println("service.getAuthorizationUrl(null)->" + authURL);
    externalContext.redirect(authURL);
}
 
开发者ID:ljug,项目名称:java-tutorials,代码行数:22,代码来源:LoginManager.java

示例12: isOrganizationMember

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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

示例13: storeConnectedAccountId

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
public ConnectResult storeConnectedAccountId(String code, Function<ConfigurationKeys, Configuration.ConfigurationPathKey> keyResolver) {
    try {
        String connectClientID = configurationManager.getRequiredValue(keyResolver.apply(STRIPE_CONNECT_CLIENT_ID));
        String clientSecret = getSystemApiKey();
        OAuth20Service service = new ServiceBuilder(connectClientID).apiSecret(clientSecret).build(new StripeConnectApi());
        Map<String, String> token = Json.fromJson(service.getAccessToken(code).getRawResponse(), new TypeReference<Map<String, String>>() {});
        String accountId = token.get("stripe_user_id");
        if(accountId != null) {
            configurationManager.saveConfig(keyResolver.apply(ConfigurationKeys.STRIPE_CONNECTED_ID), accountId);
        }
        return new ConnectResult(accountId, accountId != null, token.get("error_message"));
    } catch (Exception e) {
        log.error("cannot retrieve account ID", e);
        return new ConnectResult(null, false, e.getMessage());
    }
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:17,代码来源:StripeManager.java

示例14: processResponse

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的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

示例15: createService

import com.github.scribejava.core.oauth.OAuth20Service; //导入依赖的package包/类
private OAuth20Service createService (ResourceBundle secrets) {
    return new ServiceBuilder()
            .apiKey(secrets.getString("facebookId"))
            .apiSecret(secrets.getString("facebookSecret"))
            .callback(secrets.getString("callback"))
            .grantType("client_credentials")
            .build(FacebookApi.instance());
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:9,代码来源:FacebookAppLogin.java


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