vapor-community / Imperial

Federated Authentication with OAuth providers
MIT License
153 stars 48 forks source link

Session access token encoding error for Facebook callback #68

Open jstorm31 opened 3 years ago

jstorm31 commented 3 years ago

I'm using Facebook provider for authentication in my Vapor 4 app. Everything works fine on localhost, but I get the following error for callback URL for the app deployed on Heroku: invalidValue("long_fb_code_here", Swift.EncodingError.Context(codingPath: [], debugDescription: "Top-level String encoded as string JSON fragment.", underlyingError: nil)). I've found out this happens when setting a session access token in FacebookRouter.swift:52. For some reason the encoder has troubles with encoding the received access token as a string in Sessions+Imperial.swift:62.

As I noted it works fine on localhost which is really strange and I have no clue why. 😅 I have everything set up fine on Facebook side. As a temporary workaround I forked this repo and replaced try session.setAccessToken(accessToken) with session.data["access_token"] = accessToken. That works fine. I really wonder why this is an issue only in the deployed app.

If it is relevant, I use fluent as storage for sessions.

0xTim commented 3 years ago

Hmm that's weird. I wonder if it's a Fluent issue 🤔

The only way that line could fail would be if it's trying to set invalid data to JSON. Is this still reproducible?