Gathering detailed insights and metrics for humtum-action-cable-react-jwt
Gathering detailed insights and metrics for humtum-action-cable-react-jwt
npm install humtum-action-cable-react-jwt
Typescript
Module System
Node Version
NPM Version
72.7
Supply Chain
98.4
Quality
75.3
Maintenance
100
Vulnerability
81.3
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
548
Last Day
1
Last Week
1
Last Month
17
Last Year
79
GPL-3.0 License
29 Commits
1 Watchers
1 Branches
Updated on May 20, 2020
Latest Version
0.0.2
Package Id
humtum-action-cable-react-jwt@0.0.2
Unpacked Size
59.13 kB
Size
17.54 kB
File Count
4
NPM Version
6.14.5
Node Version
13.11.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-87.5%
1
Compared to previous week
Last Month
325%
17
Compared to previous month
Last Year
-2.5%
79
Compared to previous year
No dependencies detected.
Same as action-cable-react, but allows authenticating websockets using JWTs
Forked for humtum platform
Yarn:
1yarn add humtum-action-cable-react-jwt 2
npm:
1npm install humtum-action-cable-react-jwt 2
Import action-cable-react-jwt
1import ActionCable from 'action-cable-react-jwt.js'; 2 3// if you don't use ES6 then use 4// const ActionCable = require('action-cable-react-jwt.js'); 5
Creating an actioncable websocket
1let App = {}; 2App.cable = ActionCable.createConsumer("ws://cable.example.com", jwt) // place your jwt here 3 4// you shall also use this.cable = ActionCable.createConsumer(...) 5// to create the connection as soon as the view loads, place this in componentDidMount
Subscribing to a Channel for Receiving data
1this.subscription = App.cable.subscriptions.create({channel: "YourChannel"}, { 2 connected: function() { console.log("cable: connected") }, // onConnect 3 disconnected: function() { console.log("cable: disconnected") }, // onDisconnect 4 received: (data) => { console.log("cable received: ", data); } // OnReceive 5} 6
Send data to a channel
1this.subscription.send('hello world') 2
Call a method on channel with arguments
1this.subscription.perform('method_name', arguments) 2
In your ApplicationCable::Connection
class in Ruby add
1# app/channels/application_cable/connection.rb 2module ApplicationCable 3 class Connection < ActionCable::Connection::Base 4 identified_by :current_user 5 6 def connect 7 self.current_user = find_verified_user 8 end 9 10 private 11 12 def find_verified_user 13 begin 14 header_array = request.headers[:HTTP_SEC_WEBSOCKET_PROTOCOL].split(',') 15 token = header_array[header_array.length-1] 16 decoded_token = JWT.decode token.strip, Rails.application.secrets.secret_key_base, true, { :algorithm => 'HS256' } 17 if (current_user = User.find((decoded_token[0])['sub'])) 18 current_user 19 else 20 reject_unauthorized_connection 21 end 22 rescue 23 reject_unauthorized_connection 24 end 25 end 26 27 end 28end
And in YourChannel.rb
1# app/channels/you_channel.rb 2class LocationChannel < ApplicationCable::Channel 3 4 # calls connect in client 5 def subscribed 6 stream_from 'location_user_' + current_user.id.to_s 7 end 8 9 # calls disconnect in client 10 def unsubscribed 11 # Any cleanup needed when channel is unsubscribed 12 end 13 14 # called when send is called in client 15 def receive(params) 16 print params[:data] 17 end 18 19 # called when perform is called in client 20 def method_name(params) 21 print params[:data] 22 end 23 24end
Remove a subscription from cable
1App.cable.subscriptions.remove(this.subscription) 2 3// Place this in componentWillUnmount to remove subscription on exiting app 4
Add a subscription to cable
1App.cable.subscriptions.add(this.subscription) 2
Querying url and jwt from cable
1console.log(App.cable.jwt); 2console.log(App.cable.url); 3
Querying subscriptions and connection from cable
1console.log(App.cable.subscriptions); 2console.log(App.cable.connection); 3
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/29 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More