ruby-on-rails – 如何通过rails中的标头传递持有者令牌?
发布时间:2020-12-16 21:30:13 所属栏目:百科 来源:网络整理
导读:在我的rails应用程序中,我能够获得令牌授权:令牌令牌=’aUthEnTicAtIonTokeN’在请求标头中传递 authenticate_with_http_token do |token,options| @auth_token = tokenend 但是当我将令牌作为授权传递时:持票人令牌=’aUthEnTicAtIonTokeN’将令牌设为nil
在我的rails应用程序中,我能够获得令牌授权:令牌令牌=’aUthEnTicAtIonTokeN’在请求标头中传递
authenticate_with_http_token do |token,options| @auth_token = token end 但是当我将令牌作为授权传递时:持票人令牌=’aUthEnTicAtIonTokeN’将令牌设为nil方法. 如何在rails应用程序中通过标头传递不记名令牌? 解决方法
您可以通过以下方法获取Bearer令牌:
def bearer_token pattern = /^Bearer / header = request.headers['Authorization'] header.gsub(pattern,'') if header && header.match(pattern) end 此外,设置标题时应该是: Authorization: Bearer 'aUthEnTicAtIonTokeN' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |