https://kotlinlang.org logo
#ktor
Title
# ktor
b

bdawg.io

08/02/2018, 10:14 PM
Does ktor come with a mechanism for properly building
application/x-www-form-urlencoded
strings from a map?
1
📝 1
o

orangy

08/02/2018, 10:15 PM
Is this for connecting to other services or some other purpose?
b

bdawg.io

08/02/2018, 10:21 PM
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

orangy

08/02/2018, 10:25 PM
Hmm, aren’t you using oauth authentication feature?
b

bdawg.io

08/02/2018, 10:26 PM
I’m using Ktor to make an OAuth server. The documentation on the OAuth authentication feature suggests that it is for OAuth clients?
o

orangy

08/02/2018, 10:32 PM
Ah, I see.
Will you contribute it back as a feature? 😄
b

bdawg.io

08/02/2018, 10:51 PM
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

orangy

08/02/2018, 11:11 PM
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

Deactivated User

08/03/2018, 6:39 AM
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
2 Views