-
Notifications
You must be signed in to change notification settings - Fork 2
Add Google Health API authorization support #332
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
Changes from all commits
fe1275d
0a0f3d9
afddd1d
f5388cb
b4ffd95
4310e3d
3594ef4
8226937
954e55a
f2ff137
4765f2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,9 +28,11 @@ import org.radarbase.authorizer.doa.RestSourceUserRepositoryImpl | |
| import org.radarbase.authorizer.service.DelegatedRestSourceAuthorizationService | ||
| import org.radarbase.authorizer.service.DelegatedRestSourceAuthorizationService.Companion.FITBIT_AUTH | ||
| import org.radarbase.authorizer.service.DelegatedRestSourceAuthorizationService.Companion.GARMIN_AUTH | ||
| import org.radarbase.authorizer.service.DelegatedRestSourceAuthorizationService.Companion.GOOGLE_AUTH | ||
| import org.radarbase.authorizer.service.DelegatedRestSourceAuthorizationService.Companion.OURA_AUTH | ||
| import org.radarbase.authorizer.service.GarminOAuth2AuthorizationService | ||
| import org.radarbase.authorizer.service.GarminOauth1AuthorizationService | ||
| import org.radarbase.authorizer.service.GoogleHealthAuthorizationService | ||
| import org.radarbase.authorizer.service.OAuth2RestSourceAuthorizationService | ||
| import org.radarbase.authorizer.service.OuraAuthorizationService | ||
| import org.radarbase.authorizer.service.RegistrationService | ||
|
|
@@ -46,21 +48,21 @@ class AuthorizerResourceEnhancer( | |
| private val restSourceClients = RestSourceClients( | ||
| config.restSourceClients | ||
| .map { it.withEnv() } | ||
| .map { | ||
| when { | ||
| it.sourceType == GARMIN_AUTH && it.oauthVersion.equals("oauth2", ignoreCase = true) -> | ||
| it.copy(usesPkce = true) | ||
| it.sourceType == GOOGLE_AUTH -> | ||
| it.copy(usesPkce = true) | ||
| else -> it | ||
| } | ||
| } | ||
| .onEach { | ||
| requireNotNull(it.clientId) { "Client ID of ${it.sourceType} is missing" } | ||
| requireNotNull(it.clientSecret) { "Client secret of ${it.sourceType} is missing" } | ||
| }, | ||
| ) | ||
|
|
||
| /** | ||
| * Maps a source type to its configured OAuth version (e.g., "oauth1" or "oauth2"). | ||
| * This is used to conditionally bind the correct authorization service implementation. | ||
| * Configure via the `oauthVersion` field in `authorizer.yml` under each `restSourceClients` entry. | ||
| */ | ||
| private val sourceTypeOauthMap: Map<String, String> = config.restSourceClients.associate { | ||
| it.sourceType to it.oauthVersion.lowercase() | ||
| } | ||
|
|
||
| override val classes: Array<Class<*>> | ||
| get() = listOfNotNull( | ||
| Filters.cache, | ||
|
|
@@ -112,8 +114,9 @@ class AuthorizerResourceEnhancer( | |
| bind(DelegatedRestSourceAuthorizationService::class.java) | ||
| .to(RestSourceAuthorizationService::class.java) | ||
|
|
||
| // Bind Garmin service based on a configured oauthVersion: "oauth2" → PKCE flow, "oauth1" → legacy flow. | ||
| if (sourceTypeOauthMap[GARMIN_AUTH].equals("oauth2", ignoreCase = true)) { | ||
| // Bind Garmin service based on configured oauthVersion: "oauth2" → PKCE flow, "oauth1" → legacy flow. | ||
| val garminUsesPkce = restSourceClients.clients.firstOrNull { it.sourceType == GARMIN_AUTH }?.usesPkce == true | ||
| if (garminUsesPkce) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more readable to just use oauthVersion from config here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this in PR #333. As this PR derives |
||
| bind(GarminOAuth2AuthorizationService::class.java) | ||
| .to(RestSourceAuthorizationService::class.java) | ||
| .named(GARMIN_AUTH) | ||
|
|
@@ -134,5 +137,10 @@ class AuthorizerResourceEnhancer( | |
| .to(RestSourceAuthorizationService::class.java) | ||
| .named(OURA_AUTH) | ||
| .`in`(Singleton::class.java) | ||
|
|
||
| bind(GoogleHealthAuthorizationService::class.java) | ||
| .to(RestSourceAuthorizationService::class.java) | ||
| .named(GOOGLE_AUTH) | ||
| .`in`(Singleton::class.java) | ||
| } | ||
| } | ||
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.
is this required config? should it not be oauth2 by default?
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.
Yeah, it is OAuth 2.0 by default. I only kept it here to highlight it.
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.
likely remove it if that is the default and does not require configuration
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.
Should I do it now, or after the Garmin migration? We might be able to remove this configuration completely then, since we'll only be left with oauth 2.0.
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.
yes i think for garmin, it should still be configurable if needed (especially for legacy deployments and until Garmin forces use of OAuth2.0)