我想实现以下登录工作流程:
omniauth.auth
哈希使用OmniAuth策略可以轻松实现此过程吗?从文档中我不太清楚,大多数已经构建的策略似乎都在使用OAuth工作流程。
答案 0 :(得分:1)
显然这很容易做到。
OmniAuth策略
module OmniAuth
module Strategies
class Service
include OmniAuth::Strategy
def request_phase
redirect AUTHENTICATION_URL
end
uid { @user_details.user_id }
def extra
@user_details # Return a hash with user data
end
def callback_phase
# Configure Service SDK
@user_details = Service.user_data # Make SDK call to get user details
super
end
end
end
end
该应用
1)使用身份验证URL添加登录按钮:
<%= link_to 'Login', 'auth/service' %>
2)添加回调路由
get '/auth/service/callback', to: 'sessions#create'
3)处理控制器中的回调响应
class SessionsController < ApplicationController
def create
@user = User.find_or_create_by(service_id: auth_hash.uid)
# Handle @user
end
end