In my app, I added in User model a field twilio_video_token as a string.
When comes the time to create a token associated to a specific user, I do that:
token = Twilio::JWT::AccessToken.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_API_KEY"], ENV["TWILIO_API_SECRET"], ttl: 3600, identity: @user.name
@user.twilio_video_token = token.to_jwt
@user.save
Then, later in my app, I have an instance of a specific user.
So I access to his token like this : @user.twilio_video_token
, but it's a string, so I can't read informations stored in the token (like identity
or grants
).
How could I convert this string to be back a Twilio::JWT::AccessToken
object?
What I tried:
Using 'jwt' gem
@token = JWT.decode current_user.twilio_video_token, ENV["TWILIO_API_SECRET"], true, { algorithm: 'HS256' }
But it's a mess...
When I print @token, I see identity
into grants
!!
[{"jti"=>"SK****", "grants"=>{"identity"=>"Sylvain"}, "iss"=>"SK****", "nbf"=>1587406278, "exp"=>1587409878, "sub"=>"AC***"}, {"cty"=>"twilio-fpa;v=1", "typ"=>"JWT", "alg"=>"HS256"}]
I have to confess, I see Twilio doc as a huge labyrinth! I'm into it, but I can't tell where I am!
Thanks a lot for your help
Sylvain