Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
class AuthController < ApplicationController
ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash'.freeze

def failure
error = {
errors: [
{
status: '401',
title: 'Authentication failed',
detail: 'Authentication failed'
}
]
}

render json: error, status: :unauthorized, content_type: JSONAPI::MEDIA_TYPE
end

def callback
logger.debug({ msg: 'Received omniauth callback', omniauth: auth_hash, params: params.to_unsafe_h })

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

scope module: 'preview' do
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@
end
end

describe 'GET /auth/failure' do
it 'returns a JSON authentication failure response' do
get '/auth/failure'

expect(response).to have_http_status(:unauthorized)
expect(response.content_type).to start_with(JSONAPI::MEDIA_TYPE)

parsed = JSON.parse(response.body)
expect(parsed['errors'].first['detail']).to eq('Authentication failed')
end
end

# NOTE: In effect we're just testing omniauth-cas here, but with
# app-specific configuration and CalNet-specific data, to
# be completely sure we know what we're doing
Expand Down
Loading