Authenticate with external API in Phoenix 1.8.1 / LiveView 1.1.16

Hi everybody,

I have setup a Phoenix application using phx.gen.auth and LiveView.

I want to call an external API that is protected via OAuth2. So, after logging in, in a LiveView the user can choose to authorize with the external service, which is implemented as a redirect to the authorization URL. After login at the service and approving the usage, the service calls my callback URL with the authorization code. With the code, I want to exchange it into the access token and refresh token, store the tokens and redirect to the previous LiveView.

Unfortunately, I can not get this to work. After the redirect, I receive the callback, but my LV session is void and the user is basically logged out.

After searching the web and the forum I tried storing a session via a regular controller and also tried playing around with some JS trickery, but to no avail.

Could anybody please point me into the right direction?

Thanks in advance and have a good night.