本文整理汇总了Java中com.github.scribejava.core.oauth.OAuth20Service.getAuthorizationUrl方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth20Service.getAuthorizationUrl方法的具体用法?Java OAuth20Service.getAuthorizationUrl怎么用?Java OAuth20Service.getAuthorizationUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.scribejava.core.oauth.OAuth20Service
的用法示例。
在下文中一共展示了OAuth20Service.getAuthorizationUrl方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
示例5: retrieveAuthorizationUrl
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
@Override
protected String retrieveAuthorizationUrl(final WebContext context) throws HttpAction {
// create a specific configuration with state
final OAuthConfig config = buildOAuthConfig(context);
// create a specific service
final OAuth20Service newService = getApi().createService(config);
final String authorizationUrl = newService.getAuthorizationUrl();
logger.debug("authorizationUrl: {}", authorizationUrl);
return authorizationUrl;
}
示例6: init
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
@Override
public void init(InitContext context) {
String state = context.generateCsrfState();
OAuth20Service scribe = prepareScribe(context)
.scope("email profile")
.state(state)
.build(GoogleApi20.instance());
String url = scribe.getAuthorizationUrl();
context.redirectTo(url);
}
示例7: init
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
@Override
public void init(InitContext context) {
String state = context.generateCsrfState();
OAuth20Service scribe = newScribeBuilder(context)
.scope(getScope())
.state(state)
.build(scribeApi);
String url = scribe.getAuthorizationUrl(/* additionalParams */ );
context.redirectTo(url);
}
示例8: main
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
public static void main (String ... args) {
// Replace these with your client id and secret
mySecrets = ResourceBundle.getBundle("facebookutil/secret");
final String clientId = mySecrets.getString("googleId");
final String clientSecret = mySecrets.getString("googleSecret");
final OAuth20Service service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.scope("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.circles.write https://www.googleapis.com/auth/plus.circles.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.stream.read")
.callback("https://github.com/duke-compsci308-spring2016/voogasalad_GitDepends")
.build(GoogleApi20.instance());
Scanner in = new Scanner(System.in, "UTF-8");
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final Map<String, String> additionalParams = new HashMap<>();
additionalParams.put("access_type", "offline");
// force to retrieve refresh token (if users are asked not the first time)
additionalParams.put("prompt", "consent");
final String authorizationUrl = service.getAuthorizationUrl(additionalParams);
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
System.out.println("Trading the Request Token for an Access Token...");
OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken +
", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println("Refreshing the Access Token...");
accessToken = service.refreshAccessToken(accessToken.getRefreshToken());
System.out.println("Refreshed the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken +
", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
System.out.println("Now we're going to access a protected resource...");
while (true) {
System.out
.println("Paste fieldnames to fetch (leave empty to get profile, 'exit' to stop example)");
System.out.print(">>");
final String query = in.nextLine();
System.out.println();
final String requestUrl;
if ("exit".equals(query)) {
break;
}
else if (query == null || query.isEmpty()) {
requestUrl = PROTECTED_RESOURCE_URL;
}
else {
requestUrl = PROTECTED_RESOURCE_URL + "?fields=" + query;
}
final OAuthRequest request = new OAuthRequest(Verb.GET, requestUrl, service);
service.signRequest(accessToken, request);
final Response response = request.send();
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
}
in.close();
}
示例9: main
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
// Replace these with your client id and secret
final String clientId = "your client id";
final String clientSecret = "your client secret";
final OAuth20Service service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.scope("activity%20profile") // replace with desired scope
.callback("http://example.com") //your callback URL to store and handle the authorization code sent by Fitbit
.state("some_params")
.build(FitbitApi20.instance());
final Scanner in = new Scanner(System.in);
System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
System.out.println("Got the Authorization URL!");
System.out.println("Now go and authorize ScribeJava here:");
System.out.println(authorizationUrl);
System.out.println("And paste the authorization code here");
System.out.print(">>");
final String code = in.nextLine();
System.out.println();
// Trade the Request Token and Verfier for the Access Token
System.out.println("Trading the Request Token for an Access Token...");
final OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(if your curious it looks like this: " + accessToken
+ ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
System.out.println();
// Now let's go and ask for a protected resource!
// This will get the profile for this user
System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service);
request.addHeader("x-li-format", "json");
//add header for authentication (why make it so complicated, Fitbit?)
request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken());
final Response response = request.send();
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
System.out.println();
}
示例10: getOAuth2Url
import com.github.scribejava.core.oauth.OAuth20Service; //导入方法依赖的package包/类
private String getOAuth2Url(OAuth20Service oAuthService) {
return oAuthService.getAuthorizationUrl();
}