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

Updated getExternalId function for Oura Oauth #253

Merged
merged 2 commits into from
Jan 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ data class OuraAuthUserId(
val age: Int,
val weight: Float,
val height: Float,
val gender: String,
val biological_sex: String,
val email: String,
@SerialName("user_id") val userId: String,
@SerialName("id") val userId: String,
)

data class SignRequestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import io.ktor.client.call.body
import io.ktor.client.request.basicAuth
import io.ktor.client.request.forms.submitForm
import io.ktor.client.request.get
import io.ktor.client.request.headers
import io.ktor.client.request.url
import io.ktor.client.statement.bodyAsText
import io.ktor.http.HttpHeaders
import io.ktor.http.isSuccess
import io.ktor.http.takeFrom
import jakarta.ws.rs.core.Context
Expand Down Expand Up @@ -77,9 +79,9 @@ class OuraAuthorizationService(
private suspend fun getExternalId(accessToken: String): String = withContext(Dispatchers.IO) {
try {
val response = httpClient.get {
url {
takeFrom(OURA_USER_ID_ENDPOINT)
parameters.append("access_token", accessToken)
url(OURA_USER_ID_ENDPOINT)
headers {
append(HttpHeaders.Authorization, "Bearer $accessToken")
}
}
if (response.status.isSuccess()) {
Expand All @@ -99,6 +101,6 @@ class OuraAuthorizationService(
}

companion object {
private const val OURA_USER_ID_ENDPOINT = "https://api.ouraring.com/v1/userinfo"
private const val OURA_USER_ID_ENDPOINT = "https://api.ouraring.com/v2/usercollection/personal_info"
}
}
Loading