-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthExample.java
More file actions
34 lines (26 loc) · 1.32 KB
/
AuthExample.java
File metadata and controls
34 lines (26 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package dev.arcade.example;
import dev.arcade.client.ArcadeClient;
import dev.arcade.client.okhttp.ArcadeOkHttpClient;
import dev.arcade.models.AuthorizationResponse;
import java.util.List;
public class AuthExample {
public static void main(String[] args) {
// As the developer, you must identify the user you're authorizing
// and pass a unique identifier for them (e.g. an email or user ID) to Arcade:
String userId = System.getenv("ARCADE_USER_ID");
if (userId == null) {
throw new IllegalArgumentException("Missing environment variable ARCADE_USER_ID");
}
ArcadeClient client = ArcadeOkHttpClient.builder().fromEnv().build();
// get the auth service, and call start
AuthorizationResponse authResponse = client.auth().start(userId, "github", "oauth2", List.of("repo"));
// check the response status
authResponse
.status()
.filter(status -> status != AuthorizationResponse.Status.COMPLETED)
.flatMap(status -> authResponse.url())
.ifPresent(url -> System.out.println("Click this link to authorize: " + url));
// if the authorization is NOT complete, you can wait using the following method (for CLI applications):
client.auth().waitForCompletion(authResponse);
}
}