gpreston
I’m using Pow for user authentication and I’m having trouble figuring out how to use it with sockets. I want my sockets to pass a token on connect and use that to authorize. I have an APIAuthPlug module that follows the guide in the documentation for implementing Pow on an API. This module uses Pow.Plug.verify_token/4 to determine if a token that was passed is valid. The issue is the first parameter is a Plug.Conn struct, not a Phoenix.Socket, so what function would I use to do authentication? I use Pow.Plug.sign_token/4 to generate the tokens in the first place, so would I not be able to reuse the same API tokens for sockets?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mindok
Have you had a read through Instructions for WebSocket usage (e.g. Phoenix Channels and LiveView) · Issue #271 · pow-auth/pow · GitHub ? I don’t know if that covers your use case - there are a few options presented there.
danschultzer
Here’s what I do in a production app.
Update the
fetch/2method so we can expose aget_credentials/3method to theAPIAuthPlug:Then this can be used in the UserSocket:
Notice that I’m passing
pow_configin the connect_info. This is done in the endpoint:I’m working on a
Pow.Phoenix.Socketmodule to help with all this thoughgpreston
Sweet, thank you so much! I’ll be on the lookout for
Pow.Phoenix.SocketI tried this out but had another question, I get an error that says
(FunctionClauseError) no function clause matching in Keyword.fetch!/2. I tried usingalias Elixir.Keywordbut that didn’t seem to work, is there something I’m missing for how to access theKeywordmodule? Also, infetch/2you have itget_credentialsreturningtokenrather thanuser.Thanks again!
danschultzer
Oops, you are right, messed up the code sample. It should look like this:
I hope this works for you now
gpreston
I see, almost! Now I get the following exception:
(KeyError) key :fingerprint not found in: [renewal_token: <renewal_token>]. I can see why this happens, because increate/3we store onlyrenewal_tokeninCredentialsCachewith the lineCredentialsCache.put(store_config, access_token, {user, [renewal_token: renewal_token]})There isn’t a mention of a fingerprint anywhere other than where we are trying to get it. Where would I be implementing this, and what exactly does it mean?
danschultzer
As you can see in the above I also close all sockets when delete is called. I ran the above through the PowDemo API app to be sure it works
Rehman
I have no error but info message appear connection is not establish
[info] REFUSED CONNECTION TO AlivaWeb.UserSocket in 7ms
Transport: :websocket
Serializer: Phoenix.Socket.V2.JSONSerializer
Parameters: %{“token” => “SFMyNTY.OWIyNjY4YjktMGMzNS00OWVhLTgwOTctYTAzNzE2NjE1NDFh.6RS-n8W24BM5AKzGJN-Kiu8suguYE7HoCQPySoj6GtM”, “vsn” => “2.0.0”}