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

Fetching Oura service user id #243

Merged
merged 10 commits into from
Oct 25, 2023
Merged

Fetching Oura service user id #243

merged 10 commits into from
Oct 25, 2023

Conversation

Hsankesara
Copy link
Member

Added function to add Oura service user ID while calling requestAccessToken

@@ -51,4 +77,7 @@ class OuraAuthorizationService(
return false
}
}
companion object {
private const val Oura_USER_ID_ENDPOINT = "https://api.ouraring.com/v1/userinfo?"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be renamed to OURA_USER_ID_ENDPOINT?

logger.error("Failed to get access token for user {}", clientId)
throw HttpBadGatewayException("Service $sourceType did not provide a result")
}
val ouraUserUri = UriBuilder.fromUri(Oura_USER_ID_ENDPOINT).queryParam("access_token", accessToken.accessToken).build().toString()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this to a separate function and have the accessToken as the parameter?

private val tokenReader = objectMapper.readerFor(RestOauth2AccessToken::class.java)
private val oauthUserReader = objectMapper.readerFor(OuraAuthUserId::class.java)

override fun requestAccessToken(payload: RequestTokenPayload, sourceType: String): RestOauth2AccessToken {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just call super.requestAccessToken(..) here?

@Hsankesara
Copy link
Member Author

Thanks @mpgxvii, i've made the code changes. Have a look.

val userReq = Request.Builder().apply {
url(ouraUserUri)
}.build()
val userIdObj: OuraAuthUserId = httpClient.requestJson(userReq, oauthUserReader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also add additional response/error handling here in case the request is unsuccessful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how to do error handling after calling requestJson. Other option would be to execute request using this client.newCall(request).execute() and handle error like in GarminSourceAuthorizationService.kt. Happy to do it unless there is a better way to do the same thing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes can we just switch to the implementation similar to GarminSourceAuthorizationService. Because in case in the future when the API gets deprecated or there are issues with this endpoint, we can handle the error. (Since this is using v1 of the API)

@mpgxvii mpgxvii changed the base branch from dev to update-radar-auth-2 October 24, 2023 14:20
@mpgxvii mpgxvii changed the base branch from update-radar-auth-2 to dev October 25, 2023 09:53
@mpgxvii mpgxvii mentioned this pull request Oct 25, 2023
@mpgxvii mpgxvii self-requested a review October 25, 2023 12:57
Copy link
Member

@mpgxvii mpgxvii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Hsankesara @blootsvoets for the updates!

@mpgxvii mpgxvii merged commit ae3fd8f into dev Oct 25, 2023
5 checks passed
@Hsankesara Hsankesara deleted the oura-oauth-service-userid branch October 25, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants