仅在使用omniauth进行身份验证时配置路由

仅在使用omniauth进行身份验证时配置路由

本文介绍了仅在使用omniauth进行身份验证时配置路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个应用程序,允许用户使用omniauth-ldap对Active Directory进行身份验证。如果这是一个新用户,则成功的认证基于从AD返回的信息为他们创建一个用户。如果用户已经存在,只需登录。用户不注册应用程序,只需使用AD凭据登录。我不想让用户使用数据库凭据登录。

I have built an application which allows a user to authenticate against Active Directory using omniauth-ldap. If this is a new user, the successful authentication creates a user for them based on information returned from AD. If the user already exists, it just logs them in. Users do not register for the application, they just log in with AD credentials. And I never want the user to log in with database credentials.

我无法弄清楚如何摆脱或改变一些路由。例如,如果用户访问/ sign_in他们获得数据库身份验证。如果用户访问了sign_up,那么它们将被转到页面以注册该站点。我希望访问/ sign_in的用户被带到/ users / auth / ldap的LDAP登录。我想我需要做一个自定义路由,但我不知道我需要哪个控制器来指导用户。我想让sign_up页面完全消失。

I can't figure out how to get rid of or change around some of the routes. For example if a user visits /sign_in they get the database authentication. And if the user visits sign_up they are taken to a page to register for the site. I would like for users that visit /sign_in to be taken to the LDAP login which is /users/auth/ldap. I think I need to make a custom route, but I'm not sure which controller I need to direct the user to. And I want to make the sign_up page go away entirely.

现在我有一个允许用户使用ldap登录的链接,其路径是user_omniauth_authorize_path( :LDAP)。我只是不知道如何将它转换成我的config / routes.rb文件所理解的东西。这是我现在的路线。

Right now I have a link that allows users to log in using ldap, and the path for that is user_omniauth_authorize_path(:ldap). I'm just not sure how to translate that into something that my config/routes.rb file understands. This is what I have in routes right now.

   devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }  do
      get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
      get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
  end

当我运行rake路由时,我没有看到任何用于user_omniauth_authorize_path的路由我认为是因为该路由是由设计生成的。所以我想我需要让我的路线指向一个设计控制器,但我似乎找不到正确的路径。

When I run rake routes I do not see any route for user_omniauth_authorize_path which I presume is because that route is being generated by devise. So I think I need to have my routes point to a devise controller, but I can't seem to find the right path.

推荐答案

p>尝试添加

:skip => [:sessions, :registrations] to your routes.rb

Smth like this:

Smth like this:

devise_for :users, :skip => [:sessions, :registrations]

,而且。

这篇关于仅在使用omniauth进行身份验证时配置路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 01:44