Skip to content

Commit c381bce

Browse files
author
Bret Ambrose
committed
Dynamic login token sourcing API contract
1 parent 85728a3 commit c381bce

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/main/java/software/amazon/awssdk/crt/auth/credentials/CognitoCredentialsProvider.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static public class CognitoCredentialsProviderBuilder {
4747
private String identity;
4848
private String customRoleArn;
4949
private ArrayList<CognitoLoginTokenPair> logins = new ArrayList<CognitoLoginTokenPair>();
50+
private CognitoLoginTokenSource loginTokenSource;
5051

5152
private TlsContext tlsContext;
5253
private ClientBootstrap clientBootstrap;
@@ -148,6 +149,23 @@ public CognitoCredentialsProviderBuilder withHttpProxyOptions(HttpProxyOptions h
148149

149150
HttpProxyOptions getHttpProxyOptions() { return httpProxyOptions; }
150151

152+
/**
153+
* Sets a login token source for the credentials provider. The login token source will be used to
154+
* gather additional login tokens to submit as part of the HTTP request sent to Cognito. A login token source
155+
* allows you to dynamically add login tokens on a per-request basis. Using a login token source requires
156+
* you to follow certain requirements in order to avoid undesirable behavior. See the documentation for
157+
* `CognitoLoginTokenSource` for further details.
158+
*
159+
* @param loginTokenSource object to source login tokens from before every HTTP request to Cognito
160+
* @return The current builder
161+
*/
162+
public CognitoCredentialsProviderBuilder withLoginTokenSource(CognitoLoginTokenSource loginTokenSource) {
163+
this.loginTokenSource = loginTokenSource;
164+
165+
return this;
166+
}
167+
168+
CognitoLoginTokenSource getLoginTokenSource() { return loginTokenSource; }
151169

152170
/**
153171
* Creates a new Cognito credentials provider, based on this builder's configuration
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package software.amazon.awssdk.crt.auth.credentials;
2+
3+
import java.util.List;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Interface to allow for dynamic sourcing (ie per fetch-credentials request submitted to Cognito) of Cognito login
8+
* token pairs. It is *critical* to follow the guidance given in the documentation for `startLoginTokenFetch`
9+
*/
10+
public interface CognitoLoginTokenSource {
11+
12+
/**
13+
* Method that a Cognito credentials provider should invoke before sending a fetch credentials
14+
* request to Cognito. The CognitoLoginTokenPairs that the future gets completed with are joined
15+
* with the (static) CognitoLoginTokenPairs that were specified in the credential provider configuration
16+
* on construction. The merged set of CognitoLoginTokenPairs are added to the HTTP request sent
17+
* to Cognito that sources credentials.
18+
*
19+
* You must follow several guidelines to properly use this feature; not following these guidelines can result
20+
* in deadlocks, poor performance, or other undesirable behavior.
21+
*
22+
* 1. If you use this feature, you must complete the future or the underlying connection attempt will hang forever.
23+
* Credentials sourcing is halted until the future gets completed. If something goes wrong during
24+
* login token sourcing, complete the future exceptionally.
25+
*
26+
* 2. You must not block or wait for asynchronous operations in this function. This function is invoked from a CRT
27+
* event loop thread, and the event loop is halted until this function is returned from. If you need to perform
28+
* an asynchronous or non-trivial operation in order to source the necessary login token pairs, then you must
29+
* ensure that sourcing task executes on another thread. The easiest way to do this would be to pass the future
30+
* to a sourcing task that runs on an external executor.
31+
*/
32+
void startLoginTokenFetch(CompletableFuture<List<CognitoCredentialsProvider.CognitoLoginTokenPair>> tokenFuture);
33+
}

0 commit comments

Comments
 (0)