I am trying to authenticate in microsoft team using Azure active directory. I am able to get access token too. but after receiving the access token it is not redirecting to Microsoft Team.
Below are the code for auth-start.html
microsoftTeams.initialize();
microsoftTeams.getContext(function (msTeamsContext) {
// ADAL.js configuration
let config = {
clientId: "a6f3438e-2305-442a-9425-126f9c2c1bde",
redirectUri: window.location.origin + "/auth-end.html",
cacheLocation: "localStorage",
endpoints: {
"https://graph.microsoft.com": "https://graph.microsoft.com"
}
};
// add extra query parameters Azure AD login request
// include scope for OpenID connect and log-in hint by using the current Microsoft Teams logged-in user
config.extraQueryParameters = "scope=open+profile";
if (msTeamsContext.upn) {
config.extraQueryParameters += "&login-hint=" + encodeURIComponent(msTeamsContext.userProfileName);
}
// check if consent required for new permission
if (getUrlParameter('prompt') !== "") {
config.extraQueryParameters += "&prompt=" + getUrlParameter('prompt');
}
// override URL to Azure AD auth endpoint to include extra query parameters
config.displayCall = function (urlNavigate) {
if (urlNavigate) {
if (config.extraQueryParameters) {
urlNavigate += "&" + config.extraQueryParameters;
}
window.location.replace(urlNavigate);
}
}
// login
let authContext = new AuthenticationContext(config);
authContext.clearCache();
authContext.login();
});
function getUrlParameter(name) {
name = name.replace(/(()/, '\(').replace(/())/, '\)');
var regex = new RegExp('(\?&)' + name + '=((^&#)*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results(1).replace(/+/g, ' '));
};
Below are code for auth-end.html
microsoftTeams.initialize();
// ADAL.js configuration
let config = {
clientId: "a6f3438e-2305-442a-9425-126f9c2c1bde",
cacheLocation: "localStorage",
navigateToLoginRequestUrl: false,
endpoints: {
"https://graph.microsoft.com": "https://graph.microsoft.com"
}
};
let authContext = new AuthenticationContext(config);
// ensure page loaded via Azure AD callback
if (authContext.isCallback(window.location.hash)) {
authContext.handleWindowCallback(window.location.hash);
// Only call notifySuccess or notifyFailure if this page is in the authentication pop-up
if (window.opener) {
// if able to retrieve current user...
if (authContext.getCachedUser()) {
// get access token for Microsoft Graph
authContext.acquireToken("https://graph.microsoft.com", function (error, token) {
if (token) {
microsoftTeams.authentication.notifySuccess(token);
} else if (error) {
microsoftTeams.microsoftTeams.notifyFailure(error);
} else {
microsoftTeams.authentication.notifyFailure("UnexpectedFailure");
}
});
} else {
microsoftTeams.authentication.notifyFailure(authContext.getLoginError());
}
}
}
after this we should redirected to team tab but it is not working.