AGURRU

AGURRU

Hi I am struggling to achieve the flow that I would like. I have a form that a user submits and if successful I redirect the user to an external url to complete some actions.

This external url can POST back to my site via a web hook that I can validate and either do an action or just redirect the user to a page I want.

However the issue I am facing is that we lose the csrf_token or it become invalidated and it no longer has the current_user assigns.

How can I have it so the webhook triggers and the user returns to our site with valid csrf token and the current_user assigned?

I have no control to change the external webhook but I can validate it as being a genuine message from said source.

Could it be as simple as not redirecting a user after the form submits but opening a new tab instead?

All suggestions welcome

Showing Posts 1 to 9

LostKobrakai

LostKobrakai

I’d suggest looking a the oauth2 flow. What you described sounds like 90% of the flow they use for external authentification.

AGURRU

AGURRU OP

Yes the flow is very similar but in that situation oauth provides the current_user when there isn’t already one.

I’m still non plussed as to what’s happening to the csrf token in my case.

I am essentially going from logged in user - > external url - > back 2 minutes later and I want the session to continue.

LostKobrakai

LostKobrakai

The session does continue if the user is making the http request from their browser.

Your issue is that it’s not the user making the http request, but the external server if I understood you correctly. That web hook http request essentially has no relationship with your user and even less with the browser window your user has open.

You either want that external page to redirect the user(s browser) back to your website or you’re better of embedding the external site e.g. in an iframe.

AGURRU

AGURRU OP

I’m still stuck on this - I understand what you were saying - I have instead tried to get my controller to open the external url as a new tab (not been able to so far. Adding target = _blank didn’t work) if I did that and then had the webhook post to an unauthenticated route without the csrf plug could that work?

Kurisu

Kurisu

Why not redirect the user to a personalized URL that automatically authenticates them? The URL could contain a one-time temporary token, for example. Of course, with this model, you have to trust the application behind the external URL to actually redirect your user to your custom URL.

But perhaps I’ve misunderstood your concern?

AGURRU

AGURRU OP

Can you help me walk this through a little bit more? This is my initial thought → When I direct the user to the external url I am able to dictate the url they are posted back to.

  1. Generate a 1 time token with a webhook context (in the user_token table)
  2. Set redirect url to xxxxx.com/webhook/:token
  3. user returns - check user_token table for the token & validate the webhook.
    4a. If i have both - redirect (if i do this to a :requires_authentication url will they have to log in or will it now work as they are coming from my domain and application?
    4b. If 3 fails → flush tokens (session and webhook) and send to homepage?

I’m just not confident this will work - will I not hit a csrf token error or session error trying to do this flow?

derek-zhou

derek-zhou

You can’t; if the browser attaches your session cookie with cross site posts then all hell breaks loose. Think about all the phishing sites / emails out there.

The best you can do is redirect and post again. I had a blog post on this: Pass data from site A to site B Basically, you let the user confirm the data again.

AGURRU

AGURRU OP

I think this is essentially what I have mentioned in my last post BUT you’re saying you don’t need the webhook_token I spoke of. So long as the redirect comes from my app to my app all should be well?

derek-zhou

derek-zhou

Redirect from same domain will have the session cookie.

If you want to give the user a chance to double check the data, you don’t need to have a one time security token. If you want to make the process one click less; you could use a one time token to look up the user_id, so you don’t need the session cookie. However, then you really need to trust this 3rd party site not to forge the data.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews