Skip to content

Commit 33cbee9

Browse files
Add IDTokenSource Interface (#433)
## What changes are proposed in this pull request? This PR adds the foundational components for OIDC support in the Databricks Java SDK: **IDToken Class:** Encapsulates ID tokens from identity providers for OAuth flows. **IDTokenSource** Interface: Defines a standard for retrieving ID tokens. ## How is this tested? - Unit tests added for the IDToken class. - IDTokenSource is not tested, as no implementation exists yet. NO_CHANGELOG=true --------- Co-authored-by: Parth Bansal <[email protected]>
1 parent 9b3c55e commit 33cbee9

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.databricks.sdk.core.oauth;
2+
3+
/**
4+
* Represents an ID Token provided by an identity provider from an OAuth flow. This token can later
5+
* be exchanged for an access token.
6+
*/
7+
public class IDToken {
8+
// The string value of the ID Token
9+
private final String value;
10+
11+
/**
12+
* Constructs an IDToken with a value.
13+
*
14+
* @param value The ID Token string.
15+
*/
16+
public IDToken(String value) {
17+
if (value == null || value.isEmpty()) {
18+
throw new IllegalArgumentException("ID Token value cannot be null or empty");
19+
}
20+
this.value = value;
21+
}
22+
23+
/**
24+
* Returns the value of the ID Token.
25+
*
26+
* @return The string representation of the ID Token.
27+
*/
28+
public String getValue() {
29+
return value;
30+
}
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.databricks.sdk.core.oauth;
2+
3+
/** IDTokenSource is anything that returns an IDToken given an audience. */
4+
public interface IDTokenSource {
5+
/**
6+
* Retrieves an ID Token for the specified audience.
7+
*
8+
* @param audience The intended recipient of the ID Token.
9+
* @return An {@link IDToken} containing the token value.
10+
*/
11+
IDToken getIDToken(String audience);
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.databricks.sdk.core.oauth;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class IDTokenTest {
9+
10+
private static final String accessToken = "testIdToken";
11+
12+
@Test
13+
void testIDTokenWithValue() {
14+
IDToken idToken = new IDToken(accessToken);
15+
assertEquals(accessToken, idToken.getValue());
16+
}
17+
18+
@Test
19+
void testIDTokenWithNullValue() {
20+
assertThrows(IllegalArgumentException.class, () -> new IDToken(null));
21+
}
22+
}

0 commit comments

Comments
 (0)