-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
@@ -51,4 +77,7 @@ class OuraAuthorizationService( | |||
return false | |||
} | |||
} | |||
companion object { | |||
private const val Oura_USER_ID_ENDPOINT = "https://api.ouraring.com/v1/userinfo?" |
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 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() |
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.
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 { |
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 we just call super.requestAccessToken(..)
here?
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) |
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.
I think we can also add additional response/error handling here in case the request is unsuccessful.
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.
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
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 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)
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.
LGTM, thanks @Hsankesara @blootsvoets for the updates!
Added function to add Oura service user ID while calling
requestAccessToken