Fix issues with Microsoft Provider (#6702)

This commit is contained in:
Tarang
2023-03-20 17:57:43 +11:00
committed by GitHub
parent d2aa5f4c69
commit 0c9f129c74
3 changed files with 5 additions and 4 deletions

View File

@@ -7,11 +7,12 @@ class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts
redirect_url = microsoft_client.auth_code.authorize_url(
{
redirect_uri: "#{base_url}/microsoft/callback",
scope: 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid',
scope: 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid profile',
prompt: 'consent'
}
)
if redirect_url
email = email.downcase
::Redis::Alfred.setex(email, Current.account.id, 5.minutes)
render json: { success: true, url: redirect_url }
else

View File

@@ -8,7 +8,7 @@ class Microsoft::CallbacksController < ApplicationController
)
inbox = find_or_create_inbox
::Redis::Alfred.delete(users_data['email'])
::Redis::Alfred.delete(users_data['email'].downcase)
redirect_to app_microsoft_inbox_agents_url(account_id: account.id, inbox_id: inbox.id)
rescue StandardError => e
ChatwootExceptionTracker.new(e).capture_exception
@@ -31,7 +31,7 @@ class Microsoft::CallbacksController < ApplicationController
end
def account_id
::Redis::Alfred.get(users_data['email'])
::Redis::Alfred.get(users_data['email'].downcase)
end
def account

View File

@@ -36,7 +36,7 @@ RSpec.describe 'Microsoft Authorization API', type: :request do
response_url = microsoft_service.microsoft_client.auth_code.authorize_url(
{
redirect_uri: "#{ENV.fetch('FRONTEND_URL', 'http://localhost:3000')}/microsoft/callback",
scope: 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid',
scope: 'offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid profile',
prompt: 'consent'
}
)