从request.headers ['HTTP_AUTHORIZATION']获取令牌

时间:2017-03-27 07:41:08

标签: ruby-on-rails ruby

在我的rails应用程序中,我需要从request.headers['HTTP_AUTHORIZATION']导出令牌。如何只从字符串中导出令牌,如下所示:

"Token token=\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHBpcmVkX2F0IjoiMjAxNy0wMy0yOCAwMDozMjozMSAtMDcwMCIsImlhdCI6MTQ5MDU5OTk1MSwiaWQiOjEsImZpcnN0X25hbWUiOiJCb3NzIiwibGFzdF9uYW1lIjoiTWFuIiwicm9sZXMiOlsiYWRtaW4iXSwiZ3Vlc3QiOmZhbHNlfQ.eMoJjqY6FFWhAHxIihQ48JeHoo7z3wWMaApSWR6t4uo\""

1 个答案:

答案 0 :(得分:6)

查看ActionController::HttpAuthentication::Token.token_and_options

token, _options = ActionController::HttpAuthentication::Token.token_and_options(request)

但请注意the following Github issue我前一段时间解雇过。但对于您的情况,在您需要使用options部分之前,这并不重要。