Downgrade kotlinx serialization
This commit is contained in:
parent
71b7a94fd5
commit
ade0f62568
7
.idea/kotlinc.xml
generated
7
.idea/kotlinc.xml
generated
@ -1,5 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="1.9" />
|
||||
<option name="languageVersion" value="1.9" />
|
||||
</component>
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.0" />
|
||||
</component>
|
||||
|
@ -41,7 +41,7 @@ android {
|
||||
compose = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.1"
|
||||
kotlinCompilerExtensionVersion = "1.5.2"
|
||||
}
|
||||
packaging {
|
||||
resources {
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.shielddagger.auth.oidc_debugger.oidc
|
||||
|
||||
import com.android.volley.AuthFailureError
|
||||
import com.android.volley.Response
|
||||
import com.android.volley.toolbox.JsonObjectRequest
|
||||
import org.json.JSONObject
|
||||
import java.io.UnsupportedEncodingException
|
||||
import java.net.URLEncoder
|
||||
|
||||
class JsonFormRequest(
|
||||
method: Int,
|
||||
url: String?,
|
||||
private var params: MutableMap<String, String>,
|
||||
listener: Response.Listener<JSONObject>?,
|
||||
errorListener: Response.ErrorListener?
|
||||
) : JsonObjectRequest(method, url, null, listener, errorListener) {
|
||||
|
||||
override fun getBodyContentType(): String {
|
||||
return "application/x-www-form-urlencoded; charset=UTF-8"
|
||||
}
|
||||
|
||||
private fun encodeParameters(params: MutableMap<String, String>, paramsEncoding: String): ByteArray {
|
||||
val encodedParams = StringBuilder()
|
||||
try {
|
||||
for ((key, value) in params) {
|
||||
String.format(
|
||||
"Request#getParams() or Request#getPostParams() returned a map "
|
||||
+ "containing a null key or value: (%s, %s). All keys "
|
||||
+ "and values must be non-null.",
|
||||
key, value
|
||||
)
|
||||
encodedParams.append(URLEncoder.encode(key, paramsEncoding))
|
||||
encodedParams.append('=')
|
||||
encodedParams.append(URLEncoder.encode(value, paramsEncoding))
|
||||
encodedParams.append('&')
|
||||
}
|
||||
return encodedParams.toString().toByteArray(charset(paramsEncoding))
|
||||
} catch (uee: UnsupportedEncodingException) {
|
||||
throw RuntimeException("Encoding not supported: $paramsEncoding", uee)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getBody(): ByteArray? {
|
||||
if (params.isNotEmpty()) {
|
||||
return encodeParameters(params, paramsEncoding)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package com.shielddagger.auth.oidc_debugger.oidc
|
||||
|
||||
import android.net.Uri
|
||||
import java.io.Serializable
|
||||
import com.android.volley.Request
|
||||
import com.android.volley.Response
|
||||
import com.android.volley.toolbox.JsonObjectRequest
|
||||
import org.json.JSONObject
|
||||
import java.util.ArrayList
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
@ -35,7 +38,7 @@ enum class OIDCPromptTypes(private val type:String){
|
||||
}
|
||||
}
|
||||
|
||||
enum class OIDCAuthState(private val type: String, message: String, success: Boolean) {
|
||||
enum class OIDCAuthState(private val type: String, val message: String, val success: Boolean) {
|
||||
CODE_OK("code_ok", "Authorization Code OK", true),
|
||||
CODE_FAIL("code_fail","Authorization Code FAIL", false),
|
||||
TOKEN_OK("token_ok", "Token OK", true),
|
||||
@ -65,6 +68,52 @@ enum class OIDCAuthState(private val type: String, message: String, success: Boo
|
||||
}
|
||||
}
|
||||
|
||||
enum class OIDCTokenErrorResponse(private val type: String, val message: String){
|
||||
INVALID_REQUEST("invalid_request", "Invalid Token Request"),
|
||||
INVALID_CLIENT("invalid_client", "Invalid Client"),
|
||||
INVALID_GRANT("invalid_grant", "Invalid Grant"),
|
||||
UNAUTHORIZED_CLIENT("unauthorized_client", "Unauthorized Client"),
|
||||
UNAUTHORIZED_GRANT_TYPE("unsupported_grant_type", "Unauthorized Grant Type"),
|
||||
INVALID_SCOPE("invalid_scope", "Invalid Scope");
|
||||
|
||||
override fun toString(): String {
|
||||
return this.type
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromString(type: String): OIDCTokenErrorResponse {
|
||||
val map = OIDCTokenErrorResponse.entries.associateBy(OIDCTokenErrorResponse::type)
|
||||
return map[type]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class OIDCTokenType(private val type: String) {
|
||||
BEARER("bearer"),
|
||||
MAC("mac");
|
||||
|
||||
override fun toString(): String {
|
||||
return this.type
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun fromString(type: String): OIDCTokenType {
|
||||
val map = OIDCTokenType.entries.associateBy(OIDCTokenType::type)
|
||||
return map[type]!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class TokenResponse(
|
||||
val error: OIDCTokenErrorResponse? = null,
|
||||
val accessToken: String? = null,
|
||||
val tokenType: OIDCTokenType? = null,
|
||||
val expiresIn: Int? = null,
|
||||
val refreshToken: String? = null,
|
||||
val scope: List<String>? = null
|
||||
)
|
||||
|
||||
@kotlinx.serialization.Serializable
|
||||
class OIDCCore(
|
||||
private val responseType: List<OIDCResponseType>,
|
||||
val scope: List<String>,
|
||||
@ -76,7 +125,6 @@ class OIDCCore(
|
||||
val clientSecret: String = "",
|
||||
private val clientAuth: ClientAuthType = ClientAuthType.BASIC
|
||||
) {
|
||||
|
||||
private var nonce:String = ""
|
||||
private var state:String = ""
|
||||
|
||||
@ -136,4 +184,50 @@ class OIDCCore(
|
||||
|
||||
return stateList
|
||||
}
|
||||
|
||||
fun getTokenFromCode(returnUri: Uri,
|
||||
responseHandler: Response.Listener<JSONObject> = Response.Listener {},
|
||||
errorHandler: Response.ErrorListener = Response.ErrorListener {}): JsonFormRequest {
|
||||
if (!responseType.contains(OIDCResponseType.CODE)){
|
||||
throw RuntimeException("Can't get token from code for a client not requesting a code response type")
|
||||
}
|
||||
if (returnUri.getQueryParameter("code") == null){
|
||||
throw RuntimeException("Getting token from code impossible - no code in return URL")
|
||||
}
|
||||
|
||||
val data = mutableMapOf<String,String>()
|
||||
data["grant_type"] = "authorization_code"
|
||||
data["code"] = returnUri.getQueryParameter("code")!!
|
||||
data["client_id"] = clientId
|
||||
data["client_secret"] = clientSecret
|
||||
data["redirect_uri"] = redirectUri
|
||||
|
||||
return JsonFormRequest(
|
||||
Request.Method.POST,
|
||||
tokenUri,
|
||||
data,
|
||||
responseHandler,
|
||||
errorHandler
|
||||
)
|
||||
}
|
||||
|
||||
fun validateTokenResponse(response: JSONObject): TokenResponse{
|
||||
if (response.has("error")) {
|
||||
return TokenResponse(
|
||||
OIDCTokenErrorResponse.fromString(response.getString("error"))
|
||||
)
|
||||
}
|
||||
|
||||
return TokenResponse(
|
||||
accessToken = response.getString("access_token"),
|
||||
tokenType = OIDCTokenType.fromString(response.getString("token_type")),
|
||||
expiresIn = if (response.has("expires_in")) response.getInt("expires_in") else null,
|
||||
refreshToken = if (response.has("refresh_token")) response.getString("refresh_token") else null,
|
||||
scope = if (response.has("scope")) response.getString("scope").split(" ") else null
|
||||
)
|
||||
}
|
||||
|
||||
fun getUserinfo(accessToken: String?): JsonObjectRequest? {
|
||||
return null
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ coreKtx = "1.15.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.2.1"
|
||||
espressoCore = "3.6.1"
|
||||
kotlinxSerializationJson = "1.8.0"
|
||||
kotlinxSerializationJson = "1.6.0"
|
||||
lifecycleRuntimeKtx = "2.8.7"
|
||||
activityCompose = "1.9.3"
|
||||
composeBom = "2024.12.01"
|
||||
|
Loading…
x
Reference in New Issue
Block a user