Jaime Vizan
12/01/2023, 4:58 PMArtem Kobzar
12/01/2023, 5:19 PMJaime Vizan
12/01/2023, 5:54 PMinit = js("{" +
"\"method\": \"GET\"," +
"\"headers\": {" +
"\"Accept\": \"application/json\""+
"}" +
"}"))
But I don't know if it is the best way to define this objectturansky
12/01/2023, 6:20 PMjso
factory function insteadturansky
12/01/2023, 6:21 PMval init: RequestInit = jso {
method = ...
}
Jaime Vizan
12/01/2023, 6:46 PMHildebrandt Tobias
12/03/2023, 12:17 AMfun newTokenRequest(
code: String,
redirectUri: String,
): Promise<Response>{
val fetchURL = "${environment.KEYCLOAK_URL}/realms/${environment.KEYCLOAK_REALM}/protocol/openid-connect/token"
val body = "grant_type=authorization_code&client_id=${environment.KEYCLOAK_CLIENT}&code=$code&redirect_uri=$redirectUri"
val request = RequestInit(
method = "POST",
// The POST needs the same redirect_uri as the GET that was used to fetch the code.
body = body,
headers = json(
*listOf(
Pair("Content-Type", "application/x-www-form-urlencoded")
).toTypedArray()
),
mode = RequestMode.CORS
)
return window.fetch(fetchURL, request)
}
turansky
12/03/2023, 12:21 AMheaders
- Headers can be usedHildebrandt Tobias
12/03/2023, 12:22 AMturansky
12/03/2023, 12:24 AM