Does ktor come with a mechanism for properly build...
# ktor
b
Does ktor come with a mechanism for properly building
application/x-www-form-urlencoded
strings from a map?
1
📝 1
o
Is this for connecting to other services or some other purpose?
b
I’m trying to output a OAuth 2.0 Authorization Error Response. Something along the lines of
Copy code
call.respond(401, mapOf(
    "error" to "invalid_request",
    "error_description" to "client_id is missing"
).toFormUrlEncoded())
o
Hmm, aren’t you using oauth authentication feature?
b
I’m using Ktor to make an OAuth server. The documentation on the OAuth authentication feature suggests that it is for OAuth clients?
o
Ah, I see.
Will you contribute it back as a feature? 😄
b
I’ll see what I can figure out haha. This is my first ever ktor app besides “hello world”, so I’m still getting my hands wet as it is haha
o
That’s fine! Having an OAuth server is a nice demo for a technology. I’m not yet sure how it fits into ktor features, but overall I think it’s a great thing to have
d
You can use https://ktor.io/advanced/utilities.html#url-encoded But it works with a
List<Pair<String, String>>
, so you have first to convert the map into a list of pairs. Something like:
Copy code
call.respond(401, mapOf(
    "error" to "invalid_request",
    "error_description" to "client_id is missing"
).toList().formUrlEncode())
or:
Copy code
Parameters.build {
	append("error", "invalid_request")
	append("error_description", "client_id is missing")
}.formUrlEncode()
Edit: updated the documentation to reflect this and make it easier to discover: https://github.com/ktorio/ktorio.github.io/commit/f5d5039bdfe8387312e7e10633654fe66c334359 Edit2: just noticed that you solved this already in the next thread 🙂 so just ignore this Edit3: documented what you commented in the next thread too: https://github.com/ktorio/ktorio.github.io/commit/4c224a474811778e930862b1c670851e9bd5e8b6