标签: omniauth

使用 Microsoft Graph 教程 OmniAuth::AuthenticityError Forbidden Erros 构建 Ruby on Rails 应用程序

我是 Rails 和 Microsoft Graph/Omniauth 等的完全新手,并且有点卡住了。

我已经按照Microsoft Graph 教程逐字逐句地遵循了https://docs.microsoft.com/en-us/graph/tutorials/ruby Build Ruby on Rails 应用程序。在添加 Azure AD 身份验证实现登录,我开始启动服务器应该重定向到https://login.microsoftonline.com我得到:

OmniAuth::AuthenticityError Forbidden.

当显示上述错误时,我没有被定向到登录我的 URL 是:http://localhost:3000/auth/microsoft_graph_auth。

我正在运行 Ruby 2.7。而不是 2.6.6(如文档中所述)。

有没有人有任何指示和/或建议?

提前致谢!

Application Trace | Framework Trace | Full Trace
omniauth (2.0.1) lib/omniauth/authenticity_token_protection.rb:27:in `deny'
rack-protection (2.1.0) lib/rack/protection/base.rb:54:in `react'
omniauth (2.0.1) lib/omniauth/authenticity_token_protection.rb:18:in `call!'
omniauth (2.0.1) lib/omniauth/authenticity_token_protection.rb:11:in `call'
omniauth (2.0.1) lib/omniauth/strategy.rb:236:in `request_call'
omniauth (2.0.1) lib/omniauth/strategy.rb:192:in `call!'
omniauth (2.0.1) lib/omniauth/strategy.rb:169:in `call'
omniauth (2.0.1) lib/omniauth/builder.rb:45:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails omniauth microsoft-graph-api

1
推荐指数
1
解决办法
568
查看次数

devise + omniauth设计帮助器,如current_user,user_signed_in?不工作

我使用omniauth使用设计并使用Facebook创建登录,但是有丢失设计帮助方法访问的问题,如current_user和user_signed_in?方法不起作用.

编辑

AuthenticationController

def create
    omniauth = request.env["omniauth.auth"]    
    user = User.find_by_provider_and_uid(omniauth["provider"], omniauth["uid"]) ||       User.create_with_omniauth(omniauth)    
    session[:user_id] = user.id    
    redirect_to dashboard_path(user.id), :notice => "Signed in!"    
end  
Run Code Online (Sandbox Code Playgroud)

redirect_to USercontroller仪表板方法

UserController的

before_filter  :logged_in

 def dashboard    
    @user = User.find(params[:id])   
    @comment = Comment.new    
    @comments = @user.comments.all.paginate(:page => params[:page], :per_page => 5)    
 end 
Run Code Online (Sandbox Code Playgroud)

所以这里控制应该在检查ApplicationController中的logged_in方法后转到dashboard方法

ApplicationController中的logged_in方法

应用控制器

def logged_in    
    if user_signed_in?     
       return true    
    else    
       redirect_to root_path    
       flash[:message] = "please login"    
    end     
  end 
Run Code Online (Sandbox Code Playgroud)

当我使用Facebook在控制台生成的代码后登录时

Started GET "/users/52/dashboard" for 127.0.0.1 at Thu Mar 29 12:51:55 +0530 2012     
Processing by UsersController#dashboard …
Run Code Online (Sandbox Code Playgroud)

devise omniauth ruby-on-rails-3

0
推荐指数
1
解决办法
2669
查看次数

Rails:在哪里定义facebook app id,以便设计初始化程序和控制器可用.

我正在尝试设置fb应用程序ID(由omniauth使用),以便其全局设计初始化程序和控制器.

更多信息

我需要它在设计初始化(config/initializer/devise.rb),以便我可以设置config.omniauth:facebook,fb_app_id,fb_app_secret

试图解决方案

我尝试将此信息添加到yml文件(http://railscasts.com/episodes/85-yaml-configuration-file)中,但是,看起来像是为控制器设置了yml哈希,但我无法将其用于设计初始化.

/home/ubuntu/myapp/config/initializers/devise.rb:215:in `block in <top (required)>': uninitialized constant APP_CONFIG (NameError)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

yaml ruby-on-rails global-variables devise omniauth

0
推荐指数
1
解决办法
2091
查看次数

401未经授权使用omniauth-twitter

我试图在rails应用程序中使用omniauth-twitter,但我一开始就陷入困境,无法弄清楚原因是什么.我确实在dev.twitter.com注册了我的应用程序,我得到了CONSUMER_KEY和CONSUMER_SECRET.为了缩短测试时间,我将这两个变量直接放在initializers/omniauth.rb中

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, "an_alphanumeric_code", "some_other_alphanumeric_code"
end
Run Code Online (Sandbox Code Playgroud)

在application.html.erb布局中,我有Twitter登录的链接

<%= link_to "Sign in with Twitter", "auth/twitter" %>
Run Code Online (Sandbox Code Playgroud)

但是当我点击登录时,我没有被重定向到Twitter登录

401 Unauthorized
Run Code Online (Sandbox Code Playgroud)

我已经在SO上检查了其他问题,这不应该是计算机时间问题(我的rails服务器时间设置正确).我怀疑问题在于没有可用于测试的公共IP和服务器名称.

是否有人能够从本地127.0.0.1:3000 rails服务器上运行omniauth-twitter?

ruby-on-rails twitter-oauth omniauth

0
推荐指数
1
解决办法
744
查看次数

哪个是在Padrino子应用程序中放置初始化程序的正确途径

我正在使用OmniAuth-Facebook并将其初始化为mysubapp/app.rb:

require 'omniauth-facebook' 

class MySubApp < Padrino::Application
  register Padrino::Rendering
  register Padrino::Mailer
  register Padrino::Helpers

  enable :sessions

  SCOPE = 'email,read_stream'
  ENV['APP_ID'] = '111111111111111'
  ENV['APP_SECRET'] = '11111111111111111111111111111111'

  use OmniAuth::Builder do
    provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], :scope => SCOPE
  end
end 
Run Code Online (Sandbox Code Playgroud)

我只是想知道这是否应该与Padrino合作.这是放置我的初始化器的正确位置,或者,您可以创建一个特定的子应用程序config.ru?

ruby facebook subapplication padrino omniauth

0
推荐指数
1
解决办法
1013
查看次数

更新通过OmniAuth验证的用户数据

我有一个使用Omni-Auth GitHub宝石的Rails应用程序.用户帐户创建和通过GitHub登录工作完美无瑕!

这是我的用户模型:

  def self.from_omniauth(auth)
    find_by_github_uid(auth["uid"]) || create_from_omniauth(auth)
  end

  def self.create_from_omniauth(auth)
    create! do |user|
      user.github_uid = auth["uid"]
      user.github_token = auth["credentials"]["token"]
      user.username = auth["info"]["nickname"]
      user.email = auth["info"]["email"]
      user.full_name = auth["info"]["name"]
      user.gravatar_id = auth["extra"]["raw_info"]["gravatar_id"]
      user.blog_url = auth["extra"]["raw_info"]["blog"]
      user.company = auth["extra"]["raw_info"]["company"]
      user.location = auth["extra"]["raw_info"]["location"]
      user.hireable = auth["extra"]["raw_info"]["hireable"]
      user.bio = auth["extra"]["raw_info"]["bio"]
    end
  end
Run Code Online (Sandbox Code Playgroud)

但有时用户改变他们的生物或公司,或者他们想要被雇用,所以我不想删除旧帐户,我认为如果在更新帐户后及时更新它们会很好.

这样做的最佳做法是什么?如何使用现有的OmniAuth代码更新用户信息?

ruby-on-rails oauth oauth-2.0 omniauth

0
推荐指数
1
解决办法
460
查看次数

语法错误,意外的 '\n',期待 =&gt;

我正在登录页面上为 LinkedIn 实施 OmniAuth,但出现此错误:

SyntaxError  
/app/models/user.rb:9: syntax error, unexpected '\n', expecting =>  
Run Code Online (Sandbox Code Playgroud)

它正在查看的代码是这样的:

class User < ActiveRecord::Base  
  attr_accessor :email, :password, :password_confirmation  
  VALID_EMAIL_REGEX = /([\w+.]+)@[a-z0-9\-.]+\.[a-z]+/i   
  validates :email, presence: true,   
                    format: { with: VALID_EMAIL_REGEX },   
                    uniqueness: { case_sensitive: false }  
  validates :password, presence: true, length: { minimum: 6 }  
  validates :password_confirmation, presence: true  
  devise :rememberable, :omniauthable, :omniauth_providers => [:linkedin], :trackable
end
Run Code Online (Sandbox Code Playgroud)

请问有什么建议吗?

ruby ruby-on-rails devise omniauth ruby-on-rails-4

0
推荐指数
1
解决办法
5280
查看次数

使用 omniauth 重定向回当前页面并设计

我想在 oauth 登录后重定向回当前页面,我遵循了这个 Devise wiki并执行了以下操作:

  def after_sign_in_path_for(resource)
    sign_in_url = new_user_session_url
    if request.referer == sign_in_url
      super
    else
      request.env['omniauth.origin'] || stored_location_for(resource) || request.referer || root_path
    end
  end
Run Code Online (Sandbox Code Playgroud)

request.env['omniauth.origin']http://www.bubutravel.com/users/sign_in

stored_location_for(resource) 是零

request.refererhttp://openapi.qzone.qq.com/oauth/[omitted](我的提供者)

因此,在我的 omniauth 登录后,我再次被重定向到提供程序的 URL。

维基过时了吗?将 omniauth 登录重定向到当前页面的推荐方法是什么?

devise omniauth

0
推荐指数
1
解决办法
1089
查看次数

如何向该哈希添加“方法”?

我正在编写自定义 OAuth2 策略。我需要向expired?哈希响应添加一个方法,但我不知道该怎么做。我得到的响应给了我一个时间直到到期,但不是过期的方法本身。

在此处输入图片说明

我需要添加一个过期的?方法,不知道如何。有什么帮助吗?

hash ruby-on-rails oauth-2.0 omniauth ruby-on-rails-4

-1
推荐指数
1
解决办法
460
查看次数