spec/omniauth/strategies/auth0_spec.rb in omniauth-auth0-2.0.0 vs spec/omniauth/strategies/auth0_spec.rb in omniauth-auth0-2.1.0
- old
+ new
@@ -1,6 +1,7 @@
require 'spec_helper'
+require 'jwt'
RSpec.shared_examples 'site has valid domain url' do |url|
it { expect(subject.site).to eq(url) }
end
@@ -78,26 +79,46 @@
expect(redirect_url).to have_query('state')
expect(redirect_url).to have_query('client_id')
expect(redirect_url).to have_query('redirect_uri')
end
+ it 'redirects to hosted login page' do
+ get 'auth/auth0?connection=abcd'
+ expect(last_response.status).to eq(302)
+ redirect_url = last_response.headers['Location']
+ expect(redirect_url).to start_with('https://samples.auth0.com/authorize')
+ expect(redirect_url).to have_query('response_type', 'code')
+ expect(redirect_url).to have_query('state')
+ expect(redirect_url).to have_query('client_id')
+ expect(redirect_url).to have_query('redirect_uri')
+ expect(redirect_url).to have_query('connection', 'abcd')
+ end
+
describe 'callback' do
let(:access_token) { 'access token' }
let(:expires_in) { 2000 }
let(:token_type) { 'bearer' }
let(:refresh_token) { 'refresh token' }
- let(:id_token) { 'id token' }
let(:user_id) { 'user identifier' }
let(:state) { SecureRandom.hex(8) }
let(:name) { 'John' }
let(:nickname) { 'J' }
let(:picture) { 'some picture url' }
let(:email) { 'mail@mail.com' }
let(:email_verified) { true }
+ let(:id_token) do
+ payload = {}
+ payload['sub'] = user_id
+ payload['iss'] = "#{domain_url}/"
+ payload['aud'] = client_id
+ JWT.encode payload, client_secret, 'HS256'
+ end
+
let(:oauth_response) do
{
+ id_token: id_token,
access_token: access_token,
expires_in: expires_in,
token_type: token_type
}
end