From 0a750a62db12cc6f081d388a90122c85fd0a5568 Mon Sep 17 00:00:00 2001 From: Shaomeng Zhang Date: Wed, 10 Oct 2018 13:06:47 -0500 Subject: [PATCH 1/2] Accept access_token in callback phrase --- lib/omniauth/strategies/microsoft_graph.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/omniauth/strategies/microsoft_graph.rb b/lib/omniauth/strategies/microsoft_graph.rb index c4f9f5b..3983ce7 100644 --- a/lib/omniauth/strategies/microsoft_graph.rb +++ b/lib/omniauth/strategies/microsoft_graph.rb @@ -53,6 +53,14 @@ def authorize_params def full_name raw_info["displayName"].presence || raw_info.values_at("givenName", "surname").compact.join(' ') end + + def build_access_token + if request.params['access_token'] + ::OAuth2::AccessToken.from_hash(client, request.params.dup) + else + super + end + end end end end From 7cb167705c52cbd561b1271850e55fe5687b599b Mon Sep 17 00:00:00 2001 From: Shaomeng Zhang Date: Tue, 16 Oct 2018 14:25:59 -0500 Subject: [PATCH 2/2] Adding access_token test --- test/strategy_test.rb | 14 ++++++++++++++ test/test_helper.rb | 1 + 2 files changed, 15 insertions(+) diff --git a/test/strategy_test.rb b/test/strategy_test.rb index 73dbb4c..8c5faa2 100644 --- a/test/strategy_test.rb +++ b/test/strategy_test.rb @@ -10,3 +10,17 @@ def test_return_id_from_raw_info assert_equal '123', strategy.uid end end + +class AccessTokenTest < StrategyTestCase + def setup + super + @request.stubs(:params).returns({ 'access_token' => 'valid_access_token' }) + strategy.stubs(:client).returns(:client) + end + + def test_build_access_token + token = strategy.build_access_token + assert_equal token.token, 'valid_access_token' + assert_equal token.client, :client + end +end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 0440f5a..2583185 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,6 +16,7 @@ def setup @client_id = '123' @client_secret = '53cr3tz' + @options = {} end def strategy