Sha256: d7210752f3c0b95e3661d5a49655f2fd7e4cbb1de607695d51c5d4d5c2af8b00
Contents?: true
Size: 1.07 KB
Versions: 4
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true module AnyCable module Rails module Ext # This module adds AnyCable JWT helpers to Action Cable module JWT # Handle expired tokens here to respond with a different disconnect reason def handle_open super rescue AnyCable::JWT::ExpiredSignature logger.error "An expired JWT token was rejected" close(reason: "token_expired", reconnect: false) end def anycable_jwt_present? request.params[AnyCable.config.jwt_param].present? || request.headers["x-#{AnyCable.config.jwt_param}"].present? end def identify_from_anycable_jwt! token = request.params[AnyCable.config.jwt_param].presence || request.headers["x-#{AnyCable.config.jwt_param}"].presence identifiers = AnyCable::JWT.decode(token) identifiers.each do |k, v| public_send("#{k}=", v) end rescue AnyCable::JWT::VerificationError reject_unauthorized_connection end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems