mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
Polish code. Send only info required for each type of request
This commit is contained in:
parent
9208af89fe
commit
df8e10fac3
@ -59,13 +59,7 @@ class TokenRequestRemoteOperation(
|
|||||||
var result: RemoteOperationResult<TokenResponse>
|
var result: RemoteOperationResult<TokenResponse>
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val requestBody = FormBody.Builder()
|
val requestBody = tokenRequestParams.toRequestBody()
|
||||||
.add(HEADER_AUTHORIZATION_CODE, tokenRequestParams.authorizationCode)
|
|
||||||
.add(HEADER_GRANT_TYPE, tokenRequestParams.grantType)
|
|
||||||
.add(HEADER_REDIRECT_URI, tokenRequestParams.redirectUri)
|
|
||||||
.add(HEADER_CODE_VERIFIER, tokenRequestParams.codeVerifier)
|
|
||||||
.add(HEADER_REFRESH_TOKEN, tokenRequestParams.refreshToken.orEmpty())
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val postMethod = PostMethod(URL(tokenRequestParams.tokenEndpoint), requestBody)
|
val postMethod = PostMethod(URL(tokenRequestParams.tokenEndpoint), requestBody)
|
||||||
|
|
||||||
|
@ -23,12 +23,51 @@
|
|||||||
*/
|
*/
|
||||||
package com.owncloud.android.lib.resources.oauth.params
|
package com.owncloud.android.lib.resources.oauth.params
|
||||||
|
|
||||||
class TokenRequestParams(
|
import com.owncloud.android.lib.common.http.HttpConstants
|
||||||
|
import okhttp3.FormBody
|
||||||
|
import okhttp3.RequestBody
|
||||||
|
|
||||||
|
sealed class TokenRequestParams(
|
||||||
val tokenEndpoint: String,
|
val tokenEndpoint: String,
|
||||||
|
val clientAuth: String,
|
||||||
|
val grantType: String
|
||||||
|
) {
|
||||||
|
abstract fun toRequestBody(): RequestBody
|
||||||
|
|
||||||
|
class Authorization(
|
||||||
|
tokenEndpoint: String,
|
||||||
|
clientAuth: String,
|
||||||
|
grantType: String,
|
||||||
val authorizationCode: String,
|
val authorizationCode: String,
|
||||||
val grantType: String,
|
|
||||||
val redirectUri: String,
|
val redirectUri: String,
|
||||||
val refreshToken: String? = null,
|
val codeVerifier: String
|
||||||
val codeVerifier: String,
|
) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) {
|
||||||
val clientAuth: String
|
|
||||||
)
|
override fun toRequestBody(): RequestBody {
|
||||||
|
return FormBody.Builder()
|
||||||
|
.add(HttpConstants.HEADER_AUTHORIZATION_CODE, authorizationCode)
|
||||||
|
.add(HttpConstants.HEADER_GRANT_TYPE, grantType)
|
||||||
|
.add(HttpConstants.HEADER_REDIRECT_URI, redirectUri)
|
||||||
|
.add(HttpConstants.HEADER_CODE_VERIFIER, codeVerifier)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RefreshToken(
|
||||||
|
tokenEndpoint: String,
|
||||||
|
clientAuth: String,
|
||||||
|
grantType: String,
|
||||||
|
val refreshToken: String? = null
|
||||||
|
) : TokenRequestParams(tokenEndpoint, clientAuth, grantType) {
|
||||||
|
|
||||||
|
override fun toRequestBody(): RequestBody {
|
||||||
|
return FormBody.Builder().apply {
|
||||||
|
add(HttpConstants.HEADER_GRANT_TYPE, grantType)
|
||||||
|
if (!refreshToken.isNullOrBlank()) {
|
||||||
|
add(HttpConstants.HEADER_REFRESH_TOKEN, refreshToken)
|
||||||
|
}
|
||||||
|
}.build()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user