Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.databricks.sdk.core.oauth;

/**
* Represents an ID Token provided by an identity provider from an OAuth flow. This token can later
* be exchanged for an access token.
*/
public class IDToken {
// The string value of the ID Token
private final String value;

/**
* Constructs an IDToken with a value.
*
* @param value The ID Token string.
*/
public IDToken(String value) {
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("ID Token value cannot be null or empty");
}
this.value = value;
}

/**
* Returns the value of the ID Token.
*
* @return The string representation of the ID Token.
*/
public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.databricks.sdk.core.oauth;

/** IDTokenSource is anything that returns an IDToken given an audience. */
public interface IDTokenSource {
/**
* Retrieves an ID Token for the specified audience.
*
* @param audience The intended recipient of the ID Token.
* @return An {@link IDToken} containing the token value.
*/
IDToken getIDToken(String audience);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.databricks.sdk.core.oauth;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

public class IDTokenTest {

private static final String accessToken = "testIdToken";

@Test
void testIDTokenWithValue() {
IDToken idToken = new IDToken(accessToken);
assertEquals(accessToken, idToken.getValue());
}

@Test
void testIDTokenWithNullValue() {
assertThrows(IllegalArgumentException.class, () -> new IDToken(null));
}
}
Loading