Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Atlassian cloud api.#1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
alydemah wants to merge2 commits intoscribejava:master
base:master
Choose a base branch
Loading
fromalydemah:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,6 +55,8 @@ ScribeJava support out-of-box several HTTP clients:

### Supports all (50+) major 1.0a and 2.0 OAuth APIs out-of-the-box

* Atlassian (https://developer.atlassian.com) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AtlassianExample.java)

* Asana (https://asana.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AsanaExample.java)
* Automatic (https://www.automatic.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AutomaticExample.java)
* AWeber (http://www.aweber.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/AWeberExample.java)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
package com.github.scribejava.apis;

import com.github.scribejava.core.builder.api.DefaultApi20;

public class AtlassianApi extends DefaultApi20 {

protected AtlassianApi() {
}

private static class InstanceHolder {

private static final AtlassianApi INSTANCE = new AtlassianApi();
}

public static AtlassianApi instance() {
return InstanceHolder.INSTANCE;
}

@Override
public String getAccessTokenEndpoint() {
return "https://auth.atlassian.com/oauth/token";
}

@Override
protected String getAuthorizationBaseUrl() {
return "https://auth.atlassian.com/authorize";
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
package com.github.scribejava.apis.examples;

import com.github.scribejava.apis.AtlassianApi;
import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.model.OAuth2AccessToken;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Response;
import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.oauth.OAuth20Service;

import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

public class AtlassianExample {

private static final String PROTECTED_RESOURCE_URL = "https://api.atlassian.com/me";

private AsanaExample() {
}

@SuppressWarnings("PMD.SystemPrintln")
public static void main(String... args) throws IOException, InterruptedException, ExecutionException {
final String apiKey = "your client id";
final String apiSecret = "your client secret";
final String secretState = "secret" + new Random().nextInt(999_999);
final OAuth20Service service = new ServiceBuilder(apiKey)
.apiSecret(apiSecret)
.callback("https://localhost/")
.build(AtlassianApi.instance());
final Scanner in = new Scanner(System.in);

// Obtain Auth URL
System.out.println("Fetching the Authorication URL...");
System.out.println("Got the Authorization URL!");
final String authorizationUrl = service.getAuthorizationUrl(secretState);
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 Authorization Code for an Access Token...");
OAuth2AccessToken accessToken = service.getAccessToken(code);
System.out.println("Got the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();

System.out.println("And paste the state from server here. We have set 'secretState'='" + secretState + "'.");
System.out.print(">>");
final String value = in.nextLine();
if (secretState.equals(value)) {
System.out.println("State value does match!");
} else {
System.out.println("Ooops, state value does not match!");
System.out.println("Expected = " + secretState);
System.out.println("Got = " + value);
System.out.println();
}

System.out.println("Refreshing the Access Token...");
accessToken = service.refreshAccessToken(accessToken.getRefreshToken());
System.out.println("Refreshed the Access Token!");
System.out.println("(The raw response looks like this: " + accessToken.getRawResponse() + "')");
System.out.println();

System.out.println("Now we're going to access a protected resource...");
final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
service.signRequest(accessToken, request);
try (Response response = service.execute(request)) {
System.out.println("Got it! Lets see what we found...");
System.out.println();
System.out.println(response.getCode());
System.out.println(response.getBody());
}

System.out.println();
System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
}
}

[8]ページ先頭

©2009-2025 Movatter.jp