我在Rails 4.2上使用了devise-token-auth gem,并且我nickname在User模型中添加了一个字段.我试图通过覆盖gem控制器来实现这一点
class Users::RegistrationsController < DeviseTokenAuth::RegistrationsController
before_filter :configure_permitted_parameters
def update
#this line never shows in the logs
Rails.logger.info "I never get to run!!"
super
end
protected
# my new custom field is :nickname
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:name, :nickname,
:email, :password, :password_confirmation)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:name,
:email, :password, :password_confirmation, :nickname)
end
end
end
Run Code Online (Sandbox Code Playgroud)
路由配置如下:
Rails.application.routes.draw do
namespace :api, constraints: { format: 'json' } do
mount_devise_token_auth_for 'User', at: 'auth', controllers: {
registrations: 'users/registrations' …Run Code Online (Sandbox Code Playgroud) devise ruby-on-rails-4 http-token-authentication ruby-on-rails-4.2
我一直在阅读有关JWT的内容,据我了解,它是服务器在用户登录后发送的令牌,用户将必须在以后所有http请求中发送该令牌,这为服务器验证用户提供了一种无状态方式请求。现在我不明白的是,如果jwt在标头中发送并仅标记为http,为什么还需要一个csrf令牌来防止csrf攻击?我的理解是jwt和csrf令牌都是与用户绑定的令牌,从我的理解来看,jwt可以满足两个目的吗?我知道使用csrf令牌,因此不会接受来自其他站点的http请求,而jwt怎么不能做到这一点?什么将csrf令牌与jwt令牌分开以实现这种差异?我一直在阅读有关jwt和csrf令牌以及双提交方法的文章,
网站可以将 csrf_token 显示为 URL 参数吗?我有一种感觉,我应该看不到它,但我不太确定。如果有人能澄清这一点,我将不胜感激!
我有来自Django REST Framework的TokenAuthentication的令牌字符串.
我需要获取相应的用户对象.我该怎么做呢?
python authentication django django-rest-framework http-token-authentication
我试图使用身份验证值向服务器发送响应,它在登录时提供给我.服务器仅在发送该值时接受请求.但它适用于邮递员(见快照)但不适用于我的代码.
码
URL url = new URL(strings[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String token = "" + new String(accessToken);
con.setRequestMethod("GET");
con.setRequestProperty("AuthToken", token);
con.setReadTimeout(15000);
con.setConnectTimeout(15000);
con.setDoOutput(false);
Run Code Online (Sandbox Code Playgroud)
我也试过这样的方式
String token = "AuthToken :" + new String(accessToken);
con.setRequestProperty("Authorization", token);
Run Code Online (Sandbox Code Playgroud)