Skip to content

Commit 10935ae

Browse files
committed
Merge branch 'alexwoo/master/loginCredentialProvider_refresh1' into alexwoo/master/loginCredentialProvider_refresh_dpop
2 parents 511644f + c74d5fa commit 10935ae

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

services/signin/src/main/java/software/amazon/awssdk/services/signin/auth/LoginCredentialsProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ private RefreshResult<AwsCredentials> updateSigninCredentials() {
138138
() -> SdkClientException.create("Invalid token expiration time. You must re-authenticate.")
139139
);
140140

141-
if (shouldRefresh(currentExpirationTime, staleTime)
142-
&& shouldRefresh(currentExpirationTime, prefetchTime)) {
141+
if (shouldNotRefresh(currentExpirationTime, staleTime)
142+
&& shouldNotRefresh(currentExpirationTime, prefetchTime)) {
143143
log.debug(() -> "Using access token from disk, current expiration time is : " + currentExpirationTime);
144144
AwsCredentials credentials = tokenFromDisc.getAccessToken()
145145
.toBuilder()
@@ -241,9 +241,9 @@ public Builder toBuilder() {
241241

242242
/**
243243
*
244-
* @return true if the token should be refreshed (it is after the given refresh window, eg stale time or prefetch time)
244+
* @return true if the token does NOT need to be refreshed - it is after the given refresh window, eg stale/prefetch time.
245245
*/
246-
private static boolean shouldRefresh(Instant expiration, Duration refreshWindow) {
246+
private static boolean shouldNotRefresh(Instant expiration, Duration refreshWindow) {
247247
Instant now = Instant.now();
248248
return expiration.isAfter(now.plus(refreshWindow));
249249
}

services/signin/src/main/java/software/amazon/awssdk/services/signin/internal/DpopAuthScheme.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ private DpopAuthScheme(DpopIdentityProvider identityProvider) {
4848
this.identityProvider = Validate.paramNotNull(identityProvider, "identityProvider");
4949
}
5050

51-
public static DpopAuthScheme create(ECPublicKey ecPublicKey) {
52-
return new DpopAuthScheme(DpopIdentityProvider.create(ecPublicKey));
51+
public static DpopAuthScheme create(DpopIdentityProvider identityProvider) {
52+
return new DpopAuthScheme(identityProvider);
5353
}
5454

5555
@Override
@@ -110,9 +110,9 @@ public SignedRequest sign(SignRequest<? extends DpopIdentity> request) {
110110
public CompletableFuture<AsyncSignedRequest> signAsync(AsyncSignRequest<? extends DpopIdentity> request) {
111111
return CompletableFuture.completedFuture(
112112
AsyncSignedRequest.builder()
113-
.request(request.request())
114-
.payload(request.payload().orElse(null))
115-
.build());
113+
.request(request.request())
114+
.payload(request.payload().orElse(null))
115+
.build());
116116
}
117117
}
118118

@@ -123,8 +123,8 @@ private DpopIdentityProvider(DpopIdentity identity) {
123123
this.identity = Validate.paramNotNull(identity, "identity");
124124
}
125125

126-
public static DpopIdentityProvider create(ECPublicKey ecPublicKey) {
127-
return new DpopIdentityProvider(DpopIdentity.create(ecPublicKey));
126+
public static DpopIdentityProvider create(String dpopKeyPem) {
127+
return new DpopIdentityProvider(DpopIdentity.create(dpopKeyPem));
128128
}
129129

130130
@Override
@@ -147,15 +147,23 @@ public List<AuthSchemeOption> resolveAuthScheme(SigninAuthSchemeParams authSchem
147147
}
148148

149149
public static class DpopAuthPlugin implements SdkPlugin {
150-
private final ECPublicKey ecPublicKey;
150+
private final String dpopKeyPem;
151151

152+
private DpopAuthPlugin(String dpopKeyPem) {
153+
this.dpopKeyPem = Validate.paramNotNull(dpopKeyPem, "dpopKeyPem");
154+
}
155+
156+
public static DpopAuthPlugin create(String dpopKeyPem) {
157+
return new DpopAuthPlugin(dpopKeyPem);
158+
}
152159

153160
@Override
154161
public void configureClient(SdkServiceClientConfiguration.Builder config) {
155162
SigninServiceClientConfiguration.Builder scb =
156-
Validate.isInstanceOf(SigninServiceClientConfiguration.Builder.class, config, "bad");
163+
Validate.isInstanceOf(SigninServiceClientConfiguration.Builder.class, config,
164+
"DpopAuthPlugin must be applied to a SigninServiceClient");
157165
scb.authSchemeProvider(new DpopAuthSchemeResolver());
158-
scb.putAuthScheme(new DpopAuthScheme());
166+
scb.putAuthScheme(DpopAuthScheme.create(DpopIdentityProvider.create(dpopKeyPem)));
159167
}
160168
}
161169
}

0 commit comments

Comments
 (0)