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 support for zendesk oauth 2.0#1061

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
nishit130 wants to merge1 commit intoscribejava:master
base:master
Choose a base branch
Loading
fromnishit130:zendesk-oauth-2O-api
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
1 change: 1 addition & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,6 +112,7 @@ ScribeJava support out-of-box several HTTP clients:
* Xero (https://www.xero.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XeroExample.java)
* XING (https://www.xing.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/XingExample.java)
* Yahoo (https://www.yahoo.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/Yahoo20Example.java), [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/YahooExample.java)
* Zendesk (https://www.zendesk.com/) [example](https://github.com/scribejava/scribejava/blob/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples/ZendeskExample.java)
* check the [examples folder](https://github.com/scribejava/scribejava/tree/master/scribejava-apis/src/test/java/com/github/scribejava/apis/examples)

### Small and modular
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
package com.github.scribejava.apis;

import com.github.scribejava.apis.openid.OpenIdJsonTokenExtractor;
import com.github.scribejava.core.builder.api.DefaultApi20;
import com.github.scribejava.core.extractors.TokenExtractor;
import com.github.scribejava.core.model.OAuth2AccessToken;

public class ZendeskApi extends DefaultApi20 {

private final String serverURL;
private final String accessTokenEndpoint;
private final String authorizationBaseUrl;

protected ZendeskApi(String serverURL) {
this.serverURL = serverURL;
this.accessTokenEndpoint = serverURL + "/oauth/tokens";
this.authorizationBaseUrl = serverURL + "/oauth/authorizations/new";
}

public static ZendeskApi instance(String serverUrl) {
return new ZendeskApi(serverUrl);
}

public String getServerURL() {
return serverURL;
}

@Override
public String getAccessTokenEndpoint() {
return accessTokenEndpoint;
}

@Override
protected String getAuthorizationBaseUrl() {
return authorizationBaseUrl;
}

@Override
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() {
return OpenIdJsonTokenExtractor.instance();
}

}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
package com.github.scribejava.apis.examples;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

import com.github.scribejava.apis.ZendeskApi;
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;

@SuppressWarnings("PMD.SystemPrintln")
public class ZendeskExample {

private static final String NETWORK_NAME = "Zendesk";

public static void main(String... args) throws IOException, NoSuchAlgorithmException, KeyManagementException,
InterruptedException, ExecutionException {

// Replace these with your client id and secret
final String clientId = "Your client ID";
final String clientSecret = "Your client secret";
final String clientUrl = "Your zendesk URL";
final String callbackUrl = "Your callback URL";


final OAuth20Service service = new ServiceBuilder(clientId)
.apiSecret(clientSecret)
.callback(callbackUrl)
.defaultScope("read")
.build(ZendeskApi.instance(clientUrl));

final Scanner in = new Scanner(System.in, "UTF-8");

System.out.println("=== " + NETWORK_NAME + "'s OAuth 2.0 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 Authorization Code 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("(The raw response looks like this: " + 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...");
final OAuthRequest request = new OAuthRequest(Verb.GET, clientUrl + "/api/v2/users/me.json");
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("Thats it man! Go and build something awesome with ScribeJava! :)");

}

}

[8]ページ先頭

©2009-2025 Movatter.jp