-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add context object to pass to supplier functions (#1363)
* feat: adding context to supplier methods * adds docs * Add builder * linting * responding to docs * Adding enum support * linting * builder methods package private * Add examples on javadocs * Add test class * added docs * Add expected values to context
- Loading branch information
Showing
12 changed files
with
301 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
100 changes: 100 additions & 0 deletions
100
oauth2_http/java/com/google/auth/oauth2/ExternalAccountSupplierContext.java
This file contains 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,100 @@ | ||
package com.google.auth.oauth2; | ||
|
||
import com.google.auth.oauth2.ExternalAccountCredentials.SubjectTokenTypes; | ||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* Context object to pass relevant variables from external account credentials to suppliers. This | ||
* will be passed on any call made to {@link IdentityPoolSubjectTokenSupplier} or {@link | ||
* AwsSecurityCredentialsSupplier}. | ||
*/ | ||
public class ExternalAccountSupplierContext implements Serializable { | ||
|
||
private static final long serialVersionUID = -7852130853542313494L; | ||
|
||
private final String audience; | ||
private final String subjectTokenType; | ||
|
||
/** Internal constructor. See {@link ExternalAccountSupplierContext.Builder}. */ | ||
private ExternalAccountSupplierContext(Builder builder) { | ||
this.audience = builder.audience; | ||
this.subjectTokenType = builder.subjectTokenType; | ||
} | ||
|
||
/** | ||
* Returns the credentials' expected audience. | ||
* | ||
* @return the requested audience. For example: | ||
* "//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID". | ||
*/ | ||
public String getAudience() { | ||
return audience; | ||
} | ||
|
||
/** | ||
* Returns the credentials' expected Security Token Service subject token type based on the OAuth | ||
* 2.0 token exchange spec. | ||
* | ||
* <p>Expected values: | ||
* | ||
* <p>"urn:ietf:params:oauth:token-type:jwt" "urn:ietf:params:aws:token-type:aws4_request" | ||
* "urn:ietf:params:oauth:token-type:saml2" "urn:ietf:params:oauth:token-type:id_token" | ||
* | ||
* @return the requested subject token type. For example: "urn:ietf:params:oauth:token-type:jwt". | ||
*/ | ||
public String getSubjectTokenType() { | ||
return subjectTokenType; | ||
} | ||
|
||
static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
/** Builder for external account supplier context. */ | ||
static class Builder { | ||
|
||
protected String audience; | ||
protected String subjectTokenType; | ||
|
||
/** | ||
* Sets the Audience. | ||
* | ||
* @param audience the audience to set | ||
* @return this {@code Builder} object | ||
*/ | ||
@CanIgnoreReturnValue | ||
Builder setAudience(String audience) { | ||
this.audience = audience; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the subject token type. | ||
* | ||
* @param subjectTokenType the subjectTokenType to set. | ||
* @return this {@code Builder} object | ||
*/ | ||
@CanIgnoreReturnValue | ||
Builder setSubjectTokenType(String subjectTokenType) { | ||
this.subjectTokenType = subjectTokenType; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the subject token type. | ||
* | ||
* @param subjectTokenType the subjectTokenType to set. | ||
* @return this {@code Builder} object | ||
*/ | ||
@CanIgnoreReturnValue | ||
Builder setSubjectTokenType(SubjectTokenTypes subjectTokenType) { | ||
this.subjectTokenType = subjectTokenType.value; | ||
return this; | ||
} | ||
|
||
ExternalAccountSupplierContext build() { | ||
return new ExternalAccountSupplierContext(this); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.