Skip to content

Commit 2bc27a9

Browse files
committed
Working Github OIDC code example
1 parent 1579898 commit 2bc27a9

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed
Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1-
package com.databricks.sdk.examples;
1+
package com.databricks.example;
22

3+
import com.databricks.sdk.AccountClient;
34
import com.databricks.sdk.core.DatabricksConfig;
4-
import com.databricks.sdk.WorkspaceClient;
55
import com.databricks.sdk.service.iam.User;
6+
import com.databricks.sdk.service.iam.ListAccountGroupsRequest;
7+
import com.databricks.sdk.service.iam.Group;
68

79
/**
810
* Example demonstrating how to use GitHub OIDC authentication with Databricks.
9-
*
10-
* This example assumes you have:
11-
* 1. A Databricks workspace
12-
* 2. A service principal configured with GitHub OIDC federation
13-
* 3. The following environment variables set:
14-
* - DATABRICKS_HOST: Your Databricks workspace URL
15-
* - DATABRICKS_CLIENT_ID: Your service principal's client ID
16-
* - ACTIONS_ID_TOKEN_REQUEST_URL: GitHub Actions token request URL
17-
* - ACTIONS_ID_TOKEN_REQUEST_TOKEN: GitHub Actions token request token
1811
*/
1912
public class GithubOIDCAuthExample {
13+
2014
public static void main(String[] args) {
2115
// Create Databricks configuration with GitHub OIDC authentication
2216
DatabricksConfig config = new DatabricksConfig()
23-
.setAuthType("github-oidc");
17+
.setAuthType("github-oidc")
18+
.setHost("https://accounts.cloud.databricks.com/")
19+
.setAccountId("968367da-7edd-44f7-9dea-3e0b20b0ec97")
20+
.setClientId("dd3b5d58-5a6e-45e3-a3ae-81d8f89fc6fd");
2421

25-
// Create a workspace client
26-
WorkspaceClient workspace = new WorkspaceClient(config);
22+
AccountClient account = new AccountClient(config);
2723

2824
try {
29-
// Test the authentication by getting the current User
30-
User currentUser = workspace.currentUser().me();
31-
System.out.println("Successfully authenticated as: " + currentUser.getUserName());
32-
33-
// You can add more API calls here to test other functionality
34-
// For example:
35-
// var clusters = workspace.clusters().list();
36-
// System.out.println("Available clusters: " + clusters);
37-
25+
System.out.println("\nListing account groups:");
26+
Iterable<Group> groups = account.groups().list(new ListAccountGroupsRequest());
27+
for (Group group : groups) {
28+
System.out.println("- Group: " + group.getDisplayName() + " (ID: " + group.getId() + ")");
29+
}
30+
3831
} catch (Exception e) {
3932
System.err.println("Authentication failed: " + e.getMessage());
4033
e.printStackTrace();
4134
}
4235
}
43-
}
36+
}

0 commit comments

Comments
 (0)