Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authetication - decode cookie #17

Closed
wants to merge 1 commit into from
Closed

Authetication - decode cookie #17

wants to merge 1 commit into from

Conversation

Francynox
Copy link
Contributor

the /login endpoint sends a cookie; this cookie uses the CookieEncoding.URI_ENCODING encoding by default.

before executing the parseAuthorizationHeader method you must decode the cookie, otherwise it will never be recognized as correct

the /login endpoint sends a cookie; this cookie uses the CookieEncoding.URI_ENCODING encoding by default.

before executing the parseAuthorizationHeader method you must decode the cookie, otherwise it will never be recognized as correct
@ESchouten
Copy link
Owner

Thanks for the PR! Seems like a good fix, will look into this tomorrow.
For some reason the current implementation seems to work for me for some reason as well, time to investigate.

@ESchouten
Copy link
Owner

ESchouten commented Jul 7, 2022

@Francynox the function we use to retrieve the cookie value, has CookieEncoding.URI_ENCODING, and seems to call decodeCookieValue itself with this parameter.

public operator fun get(name: String, encoding: CookieEncoding = CookieEncoding.URI_ENCODING): String? {
  val rawValue = rawCookies[name] ?: return null
  return map.computeIfAbsent(encoding to name) { decodeCookieValue(rawValue, encoding) }
}

Could you re-verify whether the current implementation works for you or not?

@Francynox
Copy link
Contributor Author

I was trying to work on an interface in svelte that would interface with api

when I was saving cookies I had noticed that it was no longer possible to access the graphql playdround, it returned error 401

printing the value of the cookie read from the ktor server

  • for the page that had requested the cookies was correct (Bearer ey...)

  • for the playground page the cookie was decoded wrong (Bearer+ey...)

I had tried then also with Postman and it seemed that the problem was there too

Trying again now with Postman the current implementation works!!! evidently there was an error in the interface I was trying to do

@ESchouten
Copy link
Owner

Good to hear!
I appreciate you for taking the time to open a PR in order to improve the project
Thanks 👍🏻

@ESchouten ESchouten closed this Jul 8, 2022
@ESchouten
Copy link
Owner

@Francynox for authenticated endpoints in playground, you can include the token as Authorization header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants