Skip to content

Commit e3e9c01

Browse files
committed
Add route for auth/failure
1 parent fe236a8 commit e3e9c01

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

app/controllers/auth_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
class AuthController < ApplicationController
44
ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash'.freeze
55

6+
def failure
7+
render json: 'Authentication failed', status: :unauthorized
8+
end
9+
610
def callback
711
logger.debug({ msg: 'Received omniauth callback', omniauth: auth_hash, params: params.to_unsafe_h })
812

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
direct(:login) { '/auth/calnet' } # convenience to provide login_url helper
44
get '/logout', to: 'auth#logout', as: :logout
5+
get '/auth/failure', to: 'auth#failure'
56
get '/auth/:provider/callback', to: 'auth#callback', as: :omniauth_callback
67

78
scope module: 'preview' do

spec/requests/auth_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
end
4848
end
4949

50+
describe 'GET /auth/failure' do
51+
it 'returns a JSON authentication failure response' do
52+
get '/auth/failure'
53+
54+
expect(response).to have_http_status(:unauthorized)
55+
expect(response.parsed_body).to eq('Authentication failed')
56+
end
57+
end
58+
5059
# NOTE: In effect we're just testing omniauth-cas here, but with
5160
# app-specific configuration and CalNet-specific data, to
5261
# be completely sure we know what we're doing

0 commit comments

Comments
 (0)