1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Apply CR suggestions

This commit is contained in:
Abel García de Prada 2021-02-09 09:45:35 +01:00
parent f35f41688a
commit 37250fc55c
3 changed files with 11 additions and 14 deletions

View File

@ -47,7 +47,10 @@ class RegisterClientRemoteOperation(
try {
val requestBody = clientRegistrationParams.toRequestBody()
val postMethod = PostMethod(URL(clientRegistrationParams.registrationEndpoint), requestBody)
val postMethod = PostMethod(
url = URL(clientRegistrationParams.registrationEndpoint),
postRequestBody = requestBody
)
val status = client.executeHttpMethod(postMethod)

View File

@ -40,17 +40,13 @@ data class ClientRegistrationParams(
val tokenEndpointAuthMethod: String,
val applicationType: String
) {
fun toRequestBody(): RequestBody {
val jsonObject = JSONObject().apply {
fun toRequestBody(): RequestBody =
JSONObject().apply {
put(PARAM_APPLICATION_TYPE, applicationType)
put(PARAM_CLIENT_NAME, clientName)
put(PARAM_REDIRECT_URIS, JSONArray(redirectUris))
put(PARAM_TOKEN_ENDPOINT_AUTH_METHOD, tokenEndpointAuthMethod)
}
val mediaType = CONTENT_TYPE_JSON.toMediaType()
return jsonObject.toString().toRequestBody(mediaType)
}
}.toString().toRequestBody(CONTENT_TYPE_JSON.toMediaType())
companion object {
private const val PARAM_APPLICATION_TYPE = "application_type"

View File

@ -42,13 +42,12 @@ sealed class TokenRequestParams(
val redirectUri: String
) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) {
override fun toRequestBody(): RequestBody {
return FormBody.Builder()
override fun toRequestBody(): RequestBody =
FormBody.Builder()
.add(HttpConstants.OAUTH_HEADER_AUTHORIZATION_CODE, authorizationCode)
.add(HttpConstants.OAUTH_HEADER_GRANT_TYPE, grantType)
.add(HttpConstants.OAUTH_HEADER_REDIRECT_URI, redirectUri)
.build()
}
}
class RefreshToken(
@ -58,14 +57,13 @@ sealed class TokenRequestParams(
val refreshToken: String? = null
) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) {
override fun toRequestBody(): RequestBody {
return FormBody.Builder().apply {
override fun toRequestBody(): RequestBody =
FormBody.Builder().apply {
add(HttpConstants.OAUTH_HEADER_GRANT_TYPE, grantType)
if (!refreshToken.isNullOrBlank()) {
add(HttpConstants.OAUTH_HEADER_REFRESH_TOKEN, refreshToken)
}
}.build()
}
}
}