옴니아 페이스 북은 필요하지 않습니다. 이 보석의 목적은 액세스 토큰을 얻는 것뿐입니다 (그리고 사용자의 정보를 쿼리하는 것). 여기에 일이 (고안 및 omniauth - 페이스 북) 표준 설정에서 일어날 방법은 다음과 같습니다
- Omniauth는 요청의 환경에서
- Omniauth 페이스 북의 API 및 저장을 통해 사용자의 정보를 통해 가져 액세스 토큰을 획득
- Omniauth는 다음에 사용자 서명을 고안에서 제공하는 몇 가지 헬퍼를 사용하여, 당신은
- 이 콜백 방법은 검색 또는 데이터베이스에서 사용자를 생성 쓸 필요가 응용 프로그램에서 사용자 정의 콜백 메소드를 호출합니다.
이제, 당신은 이미 액세스 토큰을 가지고 주어진, 그리고 페이스 북의 API에서 사용자의 정보를 가져 오는 것은 매우 간단합니다, 당신은 실제로 omniauth - 페이스 북을 필요가 없습니다 (자세한 내용은 Devise's documentation about Omniauth 참조).
이 코드는 Devise's documentation에 주어진 예제를 기반으로합니다.
class Users::FacebookCallbacksController
def facebook
# You should test if params[:access_token] is present
# and if this request fails
facebook_data = HTTParty.get("https://graph.facebook.com/me", query: {
access_token: params[:access_token]
}).parsed_response
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(facebook_data)
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = facebook_data
redirect_to new_user_registration_url
end
end
end
참고 : 나는 Koala
sign_in_and_redirect
, set_flash_message
및 is_navigational_format?
을 포함, 페이스 북의 API를 호출하지만 다른 가능성이 존재하려면 여기를 HTTParty gem을 사용하고