You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Helper module for you to use on your app and in your Strategy# Don't add "Helper" to its name and rails won't load it has a view helper module.# "app/helpers/jwt_wrapper.rb"moduleJWTWrapperextendselfdefencode(payload,expiration=nil)expiration ||= Rails.application.secrets.jwt_expiration_minutespayload=payload.duppayload['exp']=expiration.to_i.minutes.from_now.to_iJWT.encodepayload,Rails.application.secrets.secret_key_baseenddefdecode(token)begindecoded_token=JWT.decodetoken,Rails.application.secrets.secret_key_basedecoded_token.firstrescuenilendendend
# Use this hook to configure devise mailer, warden hooks and so forth.# Many of these configuration options can be set straight in your model.Devise.setupdo |config|
(...)config.wardendo |manager|
# Registering your new Strategymanager.strategies.add(:jwt,Devise::Strategies::JsonWebToken)# Adding the new JWT Strategy to the top of Warden's list,# Scoped by what Devise would scope (typically :user)manager.default_strategies(scope: :user).unshift:jwtend(...)end
# Your actual JWT Strategy# "config/initializers/core_extensions/devise/strategies/json_web_token.rb"moduleDevisemoduleStrategiesclassJsonWebToken < Basedefvalid?request.headers['Authorization'].present?enddefauthenticate!returnfail!unlessclaimsreturnfail!unlessclaims.has_key?('user_id')success!User.find_by_idclaims['user_id']endprotected######################## PROTECTED #############################defclaimsstrategy,token=request.headers['Authorization'].split(' ')returnnilif(strategy || '').downcase != 'bearer'JWTWrapper.decode(token)rescuenilendendendend
The text was updated successfully, but these errors were encountered:
thanks for the detailed report. Please make sure your exp claim is an unix timestamp and the decode method no longer provides a default algorithm. Please make sure to set a algorithm when decoding the token.
For further debugging help I recommend to open a ticket on the devise repository.
I just "bundle update", and the this error starts appearing while invoking: before_action :authenticate_user!
Im' using device 4.3.0 and jwt gems for authentication.
My code is:
The text was updated successfully, but these errors were encountered: