草庐IT

token-based-authentication-with-n

全部标签

ruby-on-rails - 在 Ruby 中验证 Google ID token 的完整性

我正在将Google登录功能集成到Rails驱动的站点。我正在按照https://developers.google.com/identity/sign-in/web/backend-auth上的指南进行操作,但我遇到了一些问题。主要挂断是验证IDtoken的完整性段落。它概述了验证JWT的几个步骤,然后指出:Ratherthanwritingyourowncodetoperformtheseverificationsteps,westronglyrecommendusingaGoogleAPIclientlibraryforyourplatform,orcallingourtoken

ruby-on-rails - 弃用警告 : Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s)

我将我的Rails5.1.4应用更新到了5.2.0。我的一个模型中有以下范围:scope:by_category,lambda{|category_slug|category_ids=Category.find_by(slug:category_slug)&.subtree_idswhere(category_id:category_ids)}由于该范围,Rails返回以下错误:DEPRECATIONWARNING:Dangerousquerymethod(methodwhoseargumentsareusedasrawSQL)calledwithnon-attributeargume

ruby-on-rails - rails secret_key_base 在生产中未被识别

所以我正在尝试在生产环境中部署我的Rails应用程序。当我转到该页面时,出现500错误。当我转到我的错误日志时,我收到以下错误:ExceptionRuntimeErrorinRackapplicationobject(Missing`secret_key_base`for'production'environment,setthisvaluein`config/secrets.yml`)我正在运行Rails4.1,我的config/secrets.yml如下所示:development:secret_key_base:test:secret_key_base:#Donotkeeppro

ruby - 使用 oAuth token 进行 API 调用

我想在Ruby中发出oAuth请求。我浏览了一些示例,但没有一个使用oauth_token_secret和oauth_token来发出请求,他们只使用consumer_key和consumer_secret来获取oauth_token_secret和oauth_token。但是我已经有了oauth_token_secret和oauth_token。比如我试过的这个require'rubygems'require'oauth'consumer=OAuth::Consumer.new(consumer_key,consumer_secret,{:site=>"https://www.goo

ruby-on-rails - 使用 Rails 在 PaperClip 中文件上传 Base64 编码的字符串

我有一个图像文件的base64编码字符串。我需要用回形针保存它我的Controller代码是@driver=User.find(6)encoded_file=Base64.encode64(File.open('/pjt_path/public/test.jpg').read)decoded_file=Base64.decode64(encoded_file)@driver.profile_pic=StringIO.open(decoded_file)@driver.save在我的用户模型中has_attached_file:profile_pic,:styles=>{:medium=

ruby-on-rails - Rails ActiveRecord - update_all : how to update multiple fields at once with mixed type of arguments

我有一个用例,我想使用ActiveRecord::Relationupdate_all方法并指定要设置的几个字段。我使用update_all是因为可以更新很多条目,我不想将它们全部加载并一个一个地更新。其中一些需要直接的SQLSET语句,例如因为我根据另一列的值设置一列。是否有一个简单的语法与update_all一起使它可读,沿着这个=>MyModel.where(state::foo).update_all(['timespent=timespent+500',#Can'tbeanythingelsethanaSQLstatementstate::bar,#RegularRailsS

Ruby 在没有显式包含声明的情况下在子类上执行 self.included(base) 方法?

我有许多继承自一个父类(superclass)的类。作为模块定义的父类(superclass)。模块内部是一个设置一些实例变量的self.included(base)方法。所以像这样:moduleMyModuledefself.included(base)base.instance_variable_set("@my_instance_variable",{})endendclassMySuperClassincludeMyModuleendclassClassA除非我明确地将MyModule包含在ClassA和ClassB中,否则我的实例变量将不会在这两个类中设置。有没有办法确保在每

ruby-on-rails - Rails - ActionView::Base.field_error_proc 向上移动 DOM 树?

有没有办法从传入的html_tag元素向上攀登DOM树?ActionView::Base.field_error_proc=Proc.newdo|html_tag,instance|#implementationend无论如何我可以实现这个方法来向上移动DOM树并将一个类放在父div上吗?例如:EmailAddress我想在div.email上放置一个类,而不是直接在输入/标签上放置一些东西。这可以用field_error_proc方法完成还是有一个干净的替代方法?我想避免在我对每个表单字段的View中明确地这样做。(像下面这样).email{:class=>object.errors

ruby - Rails, ruby​​ : does SecureRandom. urlsafe_base64 是否需要检查 token 的唯一性?

我需要存储在我的数据库中的用户的唯一token。在我生成token的那一刻,我在使用它之前检查它在数据库中的唯一性。这是我实际需要执行的测试还是在浪费时间?我看过Ruby2.0.0APIforSecureRandom它并没有阐明我是否可以“信任”唯一性。我知道没有随机值真的是“唯一的”,并且存在的可能性是有限的。但是有了32位的十六进制值,我相信我再也不会在我的应用程序中遇到相同的值,但想问问是否有人知道这种情况下的“陷阱”。另一个考虑因素是使用SecureRandom.uuid但这本质上是相同的情况。#usageuser.password_reset_token=Generator.

ruby-on-rails - Rails SSL 问题 : (https://example. com) 与 request.base_url (http ://example. com) 不匹配

我刚刚在我的网站上安装了SSL证书。不幸的是,它破坏了登录功能。在网站上提交登录表单后,它只是重定向到主页。检查Rails日志显示此错误:(https://example.com)didn'tmatchrequest.base_url(http://example.com)这是我的虚拟主机文件。我想我需要以某种方式强制使用SSL?ServerNameexample.comServerAliaswww.example.comRedirectpermanent/https://example.com/ServerAdminhello@example.comServerNameexample