Skip to content

Commit

Permalink
fix: Identity JSON response header (#6326)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswinichile committed Feb 2, 2023
1 parent 2d245ce commit 2ab0b85
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
14 changes: 13 additions & 1 deletion app/controllers/microsoft_controller.rb
@@ -1,5 +1,17 @@
class MicrosoftController < ApplicationController
after_action :set_version_header

def identity_association
render layout: false
microsoft_indentity
end

private

def set_version_header
response.headers['Content-Length'] = { associatedApplications: [{ applicationId: @identity_json }] }.to_json.length
end

def microsoft_indentity
@identity_json = ENV.fetch('AZURE_APP_ID', nil)
end
end
7 changes: 0 additions & 7 deletions app/views/microsoft/identity_association.json.erb

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/microsoft/identity_association.json.jbuilder
@@ -0,0 +1,5 @@
json.associatedApplications do
json.array! [@identity_json] do |identity_id|
json.applicationId identity_id
end
end
6 changes: 5 additions & 1 deletion spec/controllers/microsoft_controller_spec.rb
Expand Up @@ -6,7 +6,11 @@
with_modified_env AZURE_APP_ID: 'azure-application-client-id' do
get '/.well-known/microsoft-identity-association.json'
expect(response).to have_http_status(:success)
expect(response.body).to include '"applicationId": "azure-application-client-id"'
expect(response.body).to include '"applicationId":"azure-application-client-id"'

content_length = { associatedApplications: [{ applicationId: 'azure-application-client-id' }] }.to_json.length

expect(response.headers['Content-Length']).to eq(content_length.to_s)
end
end
end
Expand Down

0 comments on commit 2ab0b85

Please sign in to comment.