Microsoft Re-authorization flow (#6268)
This commit is contained in:
5
app/controllers/microsoft_controller.rb
Normal file
5
app/controllers/microsoft_controller.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class MicrosoftController < ApplicationController
|
||||
def identity_association
|
||||
render layout: false
|
||||
end
|
||||
end
|
||||
@@ -471,6 +471,7 @@ export default {
|
||||
this.isALineChannel ||
|
||||
this.isAPIInbox ||
|
||||
(this.isAnEmailChannel && !this.inbox.provider) ||
|
||||
(this.isAnEmailChannel && this.inbox.provider === 'microsoft') ||
|
||||
this.isAWhatsAppChannel ||
|
||||
this.isAWebWidgetInbox
|
||||
) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div class="settings--content">
|
||||
<settings-section
|
||||
:title="$t('INBOX_MGMT.MICROSOFT.TITLE')"
|
||||
:sub-title="$t('INBOX_MGMT.MICROSOFT.SUBTITLE')"
|
||||
>
|
||||
<div class="smtp-details-wrap">
|
||||
<form @submit.prevent="requestAuthorization">
|
||||
<woot-submit-button
|
||||
icon="brand-twitter"
|
||||
button-text="Sign in with Microsoft"
|
||||
type="submit"
|
||||
:loading="isRequestingAuthorization"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</settings-section>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import alertMixin from 'shared/mixins/alertMixin';
|
||||
import microsoftClient from '../../../../../../api/channel/microsoftClient';
|
||||
import SettingsSection from '../../../../../../components/SettingsSection';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
SettingsSection,
|
||||
},
|
||||
mixins: [alertMixin],
|
||||
props: {
|
||||
inbox: {
|
||||
type: Object,
|
||||
default: () => ({}),
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return { isRequestingAuthorization: false };
|
||||
},
|
||||
methods: {
|
||||
async requestAuthorization() {
|
||||
try {
|
||||
this.isRequestingAuthorization = true;
|
||||
const response = await microsoftClient.generateAuthorization({
|
||||
email: this.inbox.email,
|
||||
});
|
||||
const {
|
||||
data: { url },
|
||||
} = response;
|
||||
window.location.href = url;
|
||||
} catch (error) {
|
||||
this.showAlert(this.$t('INBOX_MGMT.ADD.MICROSOFT.ERROR_MESSAGE'));
|
||||
} finally {
|
||||
this.isRequestingAuthorization = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.smtp-details-wrap {
|
||||
margin-bottom: var(--space-medium);
|
||||
}
|
||||
</style>
|
||||
@@ -90,6 +90,10 @@
|
||||
</div>
|
||||
<imap-settings :inbox="inbox" />
|
||||
<smtp-settings v-if="inbox.imap_enabled" :inbox="inbox" />
|
||||
<microsoft-reauthorize
|
||||
v-if="inbox.microsoft_reauthorization"
|
||||
:inbox="inbox"
|
||||
/>
|
||||
</div>
|
||||
<div v-else-if="isAWhatsAppChannel && !isATwilioChannel">
|
||||
<div v-if="inbox.provider_config" class="settings--content">
|
||||
@@ -109,12 +113,14 @@ import inboxMixin from 'shared/mixins/inboxMixin';
|
||||
import SettingsSection from '../../../../../components/SettingsSection';
|
||||
import ImapSettings from '../ImapSettings';
|
||||
import SmtpSettings from '../SmtpSettings';
|
||||
import MicrosoftReauthorize from '../channels/microsoft/Reauthorize';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
SettingsSection,
|
||||
ImapSettings,
|
||||
SmtpSettings,
|
||||
MicrosoftReauthorize,
|
||||
},
|
||||
mixins: [inboxMixin, alertMixin],
|
||||
props: {
|
||||
|
||||
7
app/views/microsoft/identity_association.json.erb
Normal file
7
app/views/microsoft/identity_association.json.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"associatedApplications": [
|
||||
{
|
||||
"applicationId": "<%= ENV['AZURE_APP_ID'] %>"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -350,6 +350,7 @@ Rails.application.routes.draw do
|
||||
# Routes for external service verifications
|
||||
get 'apple-app-site-association' => 'apple_app#site_association'
|
||||
get '.well-known/assetlinks.json' => 'android_app#assetlinks'
|
||||
get '.well-known/microsoft-identity-association.json' => 'microsoft#identity_association'
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Internal Monitoring Routes
|
||||
|
||||
13
spec/controllers/microsoft_controller_spec.rb
Normal file
13
spec/controllers/microsoft_controller_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe '/.well-known/microsoft-identity-association.json', type: :request do
|
||||
describe 'GET /.well-known/microsoft-identity-association.json' do
|
||||
it 'successfully retrieves assetlinks.json file' do
|
||||
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"'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user