-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcallback.js
More file actions
48 lines (44 loc) · 1.72 KB
/
callback.js
File metadata and controls
48 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable */
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { useLocation } from 'react-router-dom';
import {mtCode} from "store/actions/msTeams";
import gifloader from 'assets/images/dotsloader.gif';
import { Alert } from 'react-bootstrap';
import MsTeamsService from 'services/msTeams.service';
import { app, authentication } from '@microsoft/teams-js';
const MsTeamsCallBack = () => {
const params = new URLSearchParams(useLocation().search);
const code = params.get('code');
const state = params.get('state');
const tenantId = state.split('msteam/')[1].split('/launch')[0];
const [error, setError] = useState(null);
// Get app context and auth token
useEffect(() => {
MsTeamsService.msTeamsToken(code, tenantId)
.then((response) => {
localStorage.setItem('msteams_token', response.access_token);
localStorage.setItem('msteams_refresh_token', response.refresh_token);
localStorage.setItem('msteams_token_timestamp', new Date().toString());
window.location.replace(state);
app.initialize().then(() => {
authentication.notifySuccess('success');
}).catch((e) => {
console.log('failed to initialize msteams sdk', e);
});
}).catch((e) => {
console.log('Error getting msteams token: ', e);
setError('Failed to authenticate with Microsoft Teams');
localStorage.removeItem('msteams_token');
localStorage.removeItem('msteams_refresh_token');
window.close();
});
}, []);
return (
<div className="loader_gif">
{error && <Alert variant="danger">{error}</Alert>}
</div>
);
};
export default MsTeamsCallBack;