File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -100,14 +100,18 @@ def custom_build_access_token
100100 elsif verify_token ( request . params [ 'access_token' ] )
101101 ::OAuth2 ::AccessToken . from_hash ( client , request . params . dup )
102102 else
103- orig_build_access_token
103+ verifier = request . params [ "code" ]
104+ client . auth_code . get_token ( verifier , get_token_options ( callback_url ) , deep_symbolize ( options . auth_token_params ) )
104105 end
105106 end
106- alias_method :orig_build_access_token , :build_access_token
107107 alias_method :build_access_token , :custom_build_access_token
108108
109109 private
110110
111+ def callback_url
112+ options [ :redirect_uri ] || ( full_host + script_name + callback_path )
113+ end
114+
111115 def get_token_options ( redirect_uri )
112116 { :redirect_uri => redirect_uri } . merge ( token_params . to_hash ( :symbolize_keys => true ) )
113117 end
Original file line number Diff line number Diff line change 255255 end
256256
257257 describe '#callback_path' do
258- it 'has the correct callback path' do
258+ it 'has the correct default callback path' do
259259 expect ( subject . callback_path ) . to eq ( '/auth/google_oauth2/callback' )
260260 end
261+
262+ it 'should set the callback_path parameter if present' do
263+ @options = { :callback_path => '/auth/foo/callback' }
264+ expect ( subject . callback_path ) . to eq ( '/auth/foo/callback' )
265+ end
266+
261267 end
262268
263269 describe '#extra' do
531537 expect ( token . client ) . to eq ( :client )
532538 end
533539
534- it 'should call super if this is not an AJAX request' do
540+ it 'should use callback_url without query_string if this is not an AJAX request' do
535541 allow ( request ) . to receive ( :xhr? ) . and_return ( false )
536542 allow ( request ) . to receive ( :params ) . and_return ( 'code' => 'valid_code' )
537- expect ( subject ) . to receive ( :orig_build_access_token )
543+
544+ client = double ( :client )
545+ auth_code = double ( :auth_code )
546+ allow ( client ) . to receive ( :auth_code ) . and_return ( auth_code )
547+ allow ( subject ) . to receive ( :callback_url ) . and_return ( 'redirect_uri_without_query_string' )
548+
549+ expect ( subject ) . to receive ( :client ) . and_return ( client )
550+ expect ( auth_code ) . to receive ( :get_token ) . with ( 'valid_code' , { :redirect_uri => 'redirect_uri_without_query_string' } , { } )
538551 subject . build_access_token
539552 end
540553 end
You can’t perform that action at this time.
0 commit comments