Skip to content

Commit

Permalink
Merge pull request #177 from AuthGuard/feature/token-ttl
Browse files Browse the repository at this point in the history
Token TTL
  • Loading branch information
kmehrunes committed Oct 5, 2021
2 parents 8efd294 + 5f1b704 commit 87611fb
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public interface AuthResponse {
String getType();
Object getToken();
Object getRefreshToken();
Long getValidFor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public String getPath() {
public void addEndpoints() {
post("/authenticate", this::authenticate, ActorRoles.adminOrAuthClient());
post("/logout", this::logout, ActorRoles.adminOrAuthClient());
post("/exchange", this::exchange, ActorRoles.adminOrAuthClient());
post("/exchange/clear", this::clearToken, ActorRoles.adminOrAuthClient());
post("/exchange", this::exchange, ActorRoles.adminClient());
post("/exchange/clear", this::clearToken, ActorRoles.adminClient());
get("/exchange/attempts", this::getExchangeAttempts, ActorRoles.adminClient());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public String getPath() {

@Override
public void addEndpoints() {
post("/verify", this::verify, ActorRoles.adminClient());
post("/verify", this::verify, ActorRoles.adminOrAuthClient());
}

public abstract void verify(final Context context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public String getPath() {

@Override
public void addEndpoints() {
post("/verify", this::verify, ActorRoles.adminClient());
post("/verify", this::verify, ActorRoles.adminOrAuthClient());
}

public abstract void verify(final Context context);
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/resources/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,9 @@ components:
type: string
refreshToken:
type: string
validFor:
type: string
description: The duration for which the token will be valid (in seconds)

CreateAccountRequest:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public AuthResponseBO generateToken(final AccountBO account, final TokenRestrict
.refreshToken(refreshToken)
.entityType(EntityType.ACCOUNT)
.entityId(account.getId())
.validFor(tokenTtl.getSeconds())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public AuthResponseBO generateToken(final AccountBO account) {
.refreshToken(refreshToken)
.entityType(EntityType.ACCOUNT)
.entityId(account.getId())
.validFor(tokenTtl.getSeconds())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface AuthResponse {
String getId();
Object getToken();
Object getRefreshToken();
Long getValidFor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public AuthResponseBO generateToken(final AccountBO account, final TokenOptionsB
.token(created.getSessionToken())
.entityType(EntityType.ACCOUNT)
.entityId(account.getId())
.validFor(sessionTtl.getSeconds())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.time.Duration;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -43,6 +44,7 @@ void generateForAccount() {
.type("session_token")
.entityType(EntityType.ACCOUNT)
.entityId(account.getId())
.validFor(Duration.ofMinutes(20).getSeconds())
.build();

final AuthResponseBO actual = sessionProvider.generateToken(account);
Expand Down

0 comments on commit 87611fb

Please sign in to comment.