Gathering detailed insights and metrics for action-cable-react-jwt
Gathering detailed insights and metrics for action-cable-react-jwt
Gathering detailed insights and metrics for action-cable-react-jwt
Gathering detailed insights and metrics for action-cable-react-jwt
npm install action-cable-react-jwt
77.7
Supply Chain
99
Quality
75.3
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
25 Commits
17 Forks
5 Watching
1 Branches
4 Contributors
Updated on 22 Oct 2021
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
9.1%
325
Compared to previous day
Last week
31%
2,023
Compared to previous week
Last month
10.1%
7,823
Compared to previous month
Last year
15%
85,528
Compared to previous year
No dependencies detected.
Same as action-cable-react, but allows authenticating websockets using JWTs
Yarn:
1yarn add action-cable-react-jwt 2
npm:
1npm install 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
MIT
Copyright (c) 2017 Zeke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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@rails/actioncable
WebSocket framework for Ruby on Rails.
@kesha-antonov/react-native-action-cable
Use Rails 5+ ActionCable channels with React Native for realtime magic.
actioncable-jwt
actioncable with jwt token
actioncable-js-jwt
Rails actioncable integration with JWT Authentication for React and ReactNative