Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.7k
feat: add Feishu & Lark support#1075
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
songquanpeng wants to merge1 commit intoscribejava:masterChoose a base branch fromsongquanpeng:feat/add_feishu_lark_support
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionsREADME.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletionsscribejava-apis/src/main/java/com/github/scribejava/apis/FeishuApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.scribejava.apis; | ||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; | ||
import com.github.scribejava.core.extractors.TokenExtractor; | ||
import com.github.scribejava.core.model.OAuth2AccessToken; | ||
import com.github.scribejava.core.model.Verb; | ||
public class FeishuApi extends DefaultApi20 { | ||
protected FeishuApi() { | ||
} | ||
private static class InstanceHolder { | ||
private static final FeishuApi INSTANCE = new FeishuApi(); | ||
} | ||
public static FeishuApi instance() { | ||
return InstanceHolder.INSTANCE; | ||
} | ||
@Override | ||
public Verb getAccessTokenVerb() { | ||
return Verb.POST; | ||
} | ||
@Override | ||
public String getAccessTokenEndpoint() { | ||
return "https://open.feishu.cn/open-apis/authen/v2/oauth/token"; | ||
} | ||
@Override | ||
protected String getAuthorizationBaseUrl() { | ||
return "https://accounts.feishu.cn/open-apis/authen/v1/authorize"; | ||
} | ||
@Override | ||
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() { | ||
return OAuth2AccessTokenExtractor.instance(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletionsscribejava-apis/src/main/java/com/github/scribejava/apis/LarkApi.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.scribejava.apis; | ||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; | ||
import com.github.scribejava.core.extractors.TokenExtractor; | ||
import com.github.scribejava.core.model.OAuth2AccessToken; | ||
import com.github.scribejava.core.model.Verb; | ||
public class LarkApi extends DefaultApi20 { | ||
protected LarkApi() { | ||
} | ||
private static class InstanceHolder { | ||
private static final LarkApi INSTANCE = new LarkApi(); | ||
} | ||
public static LarkApi instance() { | ||
return InstanceHolder.INSTANCE; | ||
} | ||
@Override | ||
public Verb getAccessTokenVerb() { | ||
return Verb.POST; | ||
} | ||
@Override | ||
public String getAccessTokenEndpoint() { | ||
return "https://open.larksuite.com/open-apis/authen/v2/oauth/token"; | ||
} | ||
@Override | ||
protected String getAuthorizationBaseUrl() { | ||
return "https://accounts.larksuite.com/open-apis/authen/v1/authorize"; | ||
} | ||
@Override | ||
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() { | ||
return OAuth2AccessTokenExtractor.instance(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletionsscribejava-apis/src/test/java/com/github/scribejava/apis/examples/FeishuExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.github.scribejava.apis.examples; | ||
import java.util.Random; | ||
import java.util.Scanner; | ||
import com.github.scribejava.apis.GitHubApi; | ||
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.concurrent.ExecutionException; | ||
public class FeishuExample { | ||
private static final String NETWORK_NAME = "Feishu"; | ||
private static final String PROTECTED_RESOURCE_URL = "https://open.feishu.cn/open-apis/authen/v1/user_info"; | ||
private FeishuExample() { | ||
} | ||
@SuppressWarnings("PMD.SystemPrintln") | ||
public static void main(String... args) throws IOException, InterruptedException, ExecutionException { | ||
// Replace these with your client id and secret | ||
final String clientId = "your client id"; | ||
final String clientSecret = "your client secret"; | ||
final String secretState = "secret" + new Random().nextInt(999_999); | ||
final OAuth20Service service = new ServiceBuilder(clientId) | ||
.apiSecret(clientSecret) | ||
.defaultScope("offline_access") // replace with desired scope | ||
.callback("http://www.example.com/oauth_callback/") | ||
.build(GitHubApi.instance()); | ||
final 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 String authorizationUrl = service.getAuthorizationUrl(secretState); | ||
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("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("Trading the Authorization Code 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, 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! :)"); | ||
} | ||
} |
81 changes: 81 additions & 0 deletionsscribejava-apis/src/test/java/com/github/scribejava/apis/examples/LarkExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.github.scribejava.apis.examples; | ||
import java.util.Random; | ||
import java.util.Scanner; | ||
import com.github.scribejava.apis.GitHubApi; | ||
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.concurrent.ExecutionException; | ||
public class LarkExample { | ||
private static final String NETWORK_NAME = "Lark"; | ||
private static final String PROTECTED_RESOURCE_URL = "https://open.larksuite.com/open-apis/authen/v1/user_info"; | ||
private LarkExample() { | ||
} | ||
@SuppressWarnings("PMD.SystemPrintln") | ||
public static void main(String... args) throws IOException, InterruptedException, ExecutionException { | ||
// Replace these with your client id and secret | ||
final String clientId = "your client id"; | ||
final String clientSecret = "your client secret"; | ||
final String secretState = "secret" + new Random().nextInt(999_999); | ||
final OAuth20Service service = new ServiceBuilder(clientId) | ||
.apiSecret(clientSecret) | ||
.defaultScope("offline_access") // replace with desired scope | ||
.callback("http://www.example.com/oauth_callback/") | ||
.build(GitHubApi.instance()); | ||
final 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 String authorizationUrl = service.getAuthorizationUrl(secretState); | ||
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("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("Trading the Authorization Code 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, 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! :)"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.