mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 18:25:40 +08:00
DEV: Let OmniAuth strategies return auth result. (#7833)
This commit is contained in:
parent
f56d86a852
commit
dc5eb76551
@ -19,6 +19,15 @@ class Users::OmniauthCallbacksController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token, only: :complete
|
skip_before_action :verify_authenticity_token, only: :complete
|
||||||
|
|
||||||
def complete
|
def complete
|
||||||
|
if result = request.env["omniauth.result"]
|
||||||
|
@auth_result = result
|
||||||
|
|
||||||
|
return respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.json { render json: @auth_result.to_client_hash }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
auth = request.env["omniauth.auth"]
|
auth = request.env["omniauth.auth"]
|
||||||
raise Discourse::NotFound unless request.env["omniauth.auth"]
|
raise Discourse::NotFound unless request.env["omniauth.auth"]
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ RSpec.describe Users::OmniauthCallbacksController do
|
|||||||
|
|
||||||
after do
|
after do
|
||||||
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2] = nil
|
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2] = nil
|
||||||
|
Rails.application.env_config["omniauth.result"] = nil
|
||||||
OmniAuth.config.test_mode = false
|
OmniAuth.config.test_mode = false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -79,6 +80,25 @@ RSpec.describe Users::OmniauthCallbacksController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.complete' do
|
||||||
|
it 'will return result if present' do
|
||||||
|
result = Auth::Result.new
|
||||||
|
result.user = Fabricate(:user)
|
||||||
|
result.authenticated = true
|
||||||
|
result.destination_url = "/anotherpath"
|
||||||
|
|
||||||
|
Rails.application.env_config["omniauth.origin"] = '/somepath'
|
||||||
|
Rails.application.env_config["omniauth.result"] = result
|
||||||
|
|
||||||
|
get "/auth/test/callback.json"
|
||||||
|
response_body = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
expect(response_body["authenticated"]).to eq(true)
|
||||||
|
expect(response_body["destination_url"]).to eq("/anotherpath")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'Google Oauth2' do
|
context 'Google Oauth2' do
|
||||||
before do
|
before do
|
||||||
SiteSetting.enable_google_oauth2_logins = true
|
SiteSetting.enable_google_oauth2_logins = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user