Skip to content
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

215 show a list of redirect uri #217

Merged
merged 6 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Follow these steps to deploy CAWS:
- `manage-users`
- `view-users`
- `query-users`
- `view-clients`
- Note: this client is used by Spring to communicate with keycloak for managing accounts; if your application relies on a client that authorizes via the Keycloak service, you will need to create it depending on your application's requirements
- Under `Users` add a new Admin user and assign the `system-admin` role to it. This user will be used to invite the first researcher. Can be deactivated afterward.
- Under `Realm settings` -> `Email` configure the email settings. This is used to send out invitations to researchers/participants. The same email server can be used as the one specified in the [configuration file](src/main/resources/config/application-local.yml).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AccountController(private val accountService: AccountService) {
const val INVITE = "/invite"
const val ROLE = "/role"
const val ACCOUNT = "/{${PathVariableName.ACCOUNT_ID}}"
const val REDIRECT_URIS = "/redirect-uris"
}

@PostMapping(INVITE)
Expand Down Expand Up @@ -62,4 +63,12 @@ class AccountController(private val accountService: AccountService) {
LOGGER.info("Start GET: $ACCOUNT_BASE$ACCOUNT")
return accountService.findByUUID(accountId)
}

@GetMapping(REDIRECT_URIS)
@ResponseStatus(HttpStatus.OK)
@PreAuthorize("hasRole('RESEARCHER')")
suspend fun redirectUris(): List<String> {
LOGGER.info("Start GET: $ACCOUNT_BASE$REDIRECT_URIS")
return accountService.getRedirectUris()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ interface AccountService {
expirationSeconds: Long?,
redirectUri: String?,
): Pair<UsernameAccountIdentity, String>

suspend fun getRedirectUris(): List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,8 @@ class AccountServiceImpl(
),
)
}

override suspend fun getRedirectUris(): List<String> {
return issuerFacade.getRedirectUrisForClient()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dk.cachet.carp.webservices.security.authentication.oauth2.issuers.keycloa
import dk.cachet.carp.webservices.security.authorization.Claim
import dk.cachet.carp.webservices.security.authorization.Role

@Suppress("TooManyFunctions")
interface IssuerFacade {
suspend fun createAccount(account: Account): Account

Expand Down Expand Up @@ -38,4 +39,6 @@ interface IssuerFacade {
redirectUri: String?,
expirationSeconds: Long?,
): String

suspend fun getRedirectUrisForClient(): List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ class KeycloakFacade(
return magicLinkResponse.link
}

override suspend fun getRedirectUrisForClient(): List<String> {
val token = authenticate().accessToken

LOGGER.debug("Getting redirect URIs for client.")

val clientRepresentations =
adminClient.get().uri("/clients")
.headers {
it.setBearerAuth(token!!)
}
.retrieve()
.awaitBody<List<Map<String, Any>>>()

val wsClientRepresentation = clientRepresentations.first { it["clientId"] == clientId }

return wsClientRepresentation["redirectUris"] as? List<String> ?: emptyList()
}

private suspend fun queryAll(query: String): List<Account> {
val token = authenticate().accessToken

Expand Down