Skip to content

Commit

Permalink
Merge pull request #94 from Zensaburou/master
Browse files Browse the repository at this point in the history
Update /login to use /oauth/token
  • Loading branch information
aaguiarz authored Feb 19, 2018
2 parents 3a5cb5a + 94c0780 commit 687326f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 40 deletions.
19 changes: 10 additions & 9 deletions lib/auth0/api/authentication_endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,17 @@ def login(username, password, id_token = nil, connection_name = UP_AUTH, options
raise Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty?
raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
request_params = {
client_id: @client_id,
username: username,
password: password,
scope: options.fetch(:scope, 'openid'),
connection: connection_name,
grant_type: options.fetch(:grant_type, password),
id_token: id_token,
device: options.fetch(:device, nil)
client_id: @client_id,
client_secret: @client_secret,
username: username,
password: password,
scope: options.fetch(:scope, 'openid'),
connection: connection_name,
grant_type: options.fetch(:grant_type, password),
id_token: id_token,
device: options.fetch(:device, nil)
}
post('/oauth/ro', request_params)
post('/oauth/token', request_params)
end

# Signup using username/password
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/lib/auth0/api/api_authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
attr_reader :client, :impersonate_user, :impersonator_user, :global_client, :password

before(:all) do
@client = Auth0Client.new(v2_creds)
@client = Auth0Client.new(Credentials.v2_creds)
impersonate_username = Faker::Internet.user_name
impersonate_email = "#{entity_suffix}#{Faker::Internet.safe_email(impersonate_username)}"
@password = Faker::Internet.password
Expand Down
8 changes: 5 additions & 3 deletions spec/lib/auth0/api/authentication_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@

context '.login' do
it { expect(@instance).to respond_to(:login) }
it 'is expected to make post to /oauth/ro' do
it 'is expected to make post to /oauth/token' do
expect(@instance).to receive(:post).with(
'/oauth/ro',
client_id: @instance.client_id, username: 'test@test.com',
'/oauth/token',
client_id: @instance.client_id,
username: 'test@test.com',
client_secret: @instance.client_secret,
password: 'password', scope: 'openid', connection: 'Username-Password-Authentication',
grant_type: 'password', id_token: nil, device: nil
)
Expand Down
23 changes: 23 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
require 'dotenv'

Dotenv.load

mode = ENV['MODE'] || 'unit'

$LOAD_PATH.unshift File.expand_path('..', __FILE__)
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'rspec'
require 'rack/test'
require 'faker'
require 'auth0'

Dir['./lib/**/*.rb'].each { |f| require f }
Dir['./spec/support/**/*.rb'].each { |f| require f }
Dir['./spec/support/*.rb'].each { |f| require f }

def entity_suffix
(ENV['TRAVIS_JOB_ID'] || 'local').delete('_')
end

puts "Entity suffix is #{entity_suffix}"

require_relative "spec_helper_#{mode}"
17 changes: 0 additions & 17 deletions spec/spec_helper_full.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'coveralls'
Coveralls.wear!

Expand All @@ -10,25 +7,11 @@
add_filter '/spec/integration'
end

require 'rspec'
require 'rack/test'
require 'faker'
require 'auth0'
require 'pry'

Dir['./lib/**/*.rb'].each { |f| require f }
Dir['./spec/support/**/*.rb'].each { |f| require f }

def entity_suffix
(ENV['TRAVIS_JOB_ID'] || 'local').delete('_')
end

puts "Entity suffix is #{entity_suffix}"

RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.include Rack::Test::Methods
config.include Credentials
config.after(:suite) do
puts "Cleaning up for #{entity_suffix}"
Expand Down
9 changes: 0 additions & 9 deletions spec/spec_helper_unit.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'rspec'
require 'rack/test'
require 'faker'
require 'auth0'
Dir['./lib/**/*.rb'].each { |f| require f }
Dir['./spec/support/**/*.rb'].each { |f| require f }
RSpec.configure do |config|
config.include Rack::Test::Methods
config.fail_fast = true
end
2 changes: 2 additions & 0 deletions spec/support/credentials.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module Credentials
module_function

def v1_creds
{ client_id: ENV['CLIENT_ID'],
client_secret: ENV['CLIENT_SECRET'],
Expand Down
2 changes: 1 addition & 1 deletion spec/support/dummy_class.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DummyClass
attr_reader :domain, :client_id
attr_reader :domain, :client_id, :client_secret

def initialize
@domain = 'test.auth0.com'
Expand Down

0 comments on commit 687326f

Please sign in to comment.