-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add context object to pass to supplier functions #1363
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9386dfd
feat: adding context to supplier methods
aeitzman 266c02a
adds docs
aeitzman 6361b0a
Add builder
aeitzman 27356ed
linting
aeitzman 39dae2e
responding to docs
aeitzman 85d526f
Adding enum support
aeitzman a63f0b7
linting
aeitzman 142a5f7
builder methods package private
aeitzman 24cf2e2
Add examples on javadocs
aeitzman 5292827
Add test class
aeitzman 3e6d69a
added docs
aeitzman 03291df
Add expected values to context
aeitzman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" | ||
* | ||
aeitzman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @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. | ||
aeitzman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a copyright header?