omniauth第三方验证常见错误

本文提供了解决Rails应用中遇到的SSL连接失败和权限保护相关问题的方法,包括设置证书文件、调整环境变量以及修改验证逻辑等步骤。

1.     错误:Faraday::Error::ConnectionFailed

SSL_connect returned=1 errno=0 state=SSLv3 read servercertificate B:

Certificate verify faild

解决:在d:\rails目录下建立文件win_fetch_cacerts.rb 将网页中的信息拷贝到文件中https://raw.github.com/gist/867550/win_fetch_cacerts.rb。在c:\RailsInstaller目录下建立文件cacert.pem。在命令中执行set SSL_CERT_FILE=C:\RailsInstaller\cacert.pem。执行ruby “%d:\rails\win_fetch_cacerts.rb%” 。配置环境变量:变量名:SSL_CERT_FILE  变量值:C:\RailsInstaller\cacert.pem

2.    错误:Can’tmass-assign protected attributes: authentications_attributes         

解决:增加authentications_attributes的说明 attr_accessible : authentications_attributes

3.   错误:Can’tmass-assign protected attributes: created_at,updated_at

解决:def from_auth(auth)

     Authentication.find_by_provider_and_uid(auth[:provider],

                                            auth[:uid]).try(:admin)||

     create!(

        :nickname => auth[:info][:nickname],

        :email => auth[:info][:email],

        :authentications_attributes => [

          Authentication.new(:provider =>auth[:provider],

                             :uid =>auth[:uid]

                             ).attributes

        ]

      )                                      

End 改为

deffrom_auth(auth)

      authentication =Authentication.find_by_provider_and_uid(auth[:provider],

                                            auth[:uid]).try(:admin)

      unless authentication

        admin = create!(

          :nickname =>auth[:info][:nickname],

          :email => auth[:info][:email])

        admin.authentications.build(:provider=> auth[:provider])

      end                                      

   end


4.   错误:Validationfailed: Email can't be blank 公开的邮箱一定要填


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值