Comments (2)
The topic of authentication in Websockets connections is completely foreign to me. Sadly I can't offer any guidance here.
from tiddle.
For anyone else who comes across this and is looking for the same thing. Here is how I got Tiddle working in ActionCable.
@adamniedzielski might be worth adding to the documentation.
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
end
protected
def find_verified_user
user = User.find_for_authentication(email: request.params[:user_email])
reject_unauthorized_connection unless user
token = Tiddle::TokenIssuer.build.find_token(user, request.params[:user_token])
if token && unexpired?(token)
return user
end
reject_unauthorized_connection
end
def unexpired?(token)
return true unless token.respond_to?(:expires_in)
return true if token.expires_in.blank? || token.expires_in.zero?
Time.current <= token.last_used_at + token.expires_in
end
end
end
This isn't a perfect solution and I don't really like sending tokens via query params, but it works. Note that it makes a few assumptions and hard codes variable names (model is User, key is email and sent via a query param of user_email and token is sent via query param of user_token)
from tiddle.
Related Issues (20)
- Version 1.0 HOT 2
- Fix Rubocop offences
- DEPRECATION WARNING: ActionDispatch::IntegrationTest HOT 7
- Error after installed Tiddle HOT 3
- Can't change maximum token per user
- Support devise > 4.3.X HOT 2
- Time-based expiration mechanism for tokens HOT 7
- Remove unnecessary secure compare
- Devise 4.4 HOT 4
- [Question]: What for sending X-USER-EMAIL ?
- Update required fields for README HOT 2
- Tiddle can not work with devise 4.5.0. HOT 3
- Soft purge setting `revoked_at` instead of destroying auth tokens? HOT 2
- Devise can not be updated past version >=4.6
- Multiple types of Users HOT 1
- Token last_used_at not being updated properly HOT 5
- Tokens pile up in the database forever HOT 1
- Switch dev setup to use Docker
- Mongoid support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiddle.