web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / How to configure Singl...
Copilot Studio
Unanswered

How to configure Single Sign On in PVA with Sharepoint and Teams?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All,

 

I am trying to configure Single Sign on in Power Virtual Agent with Sharepoint. I am following the document https://docs.microsoft.com/en-us/power-virtual-agents/configure-sso

 

Below is the html code and i have added the Client ID of Canvas API,Directory ID and BOT ID.

 

<!DOCTYPE html>
<html>
<head>
 
 <script>
 var clientApplication;
 (function () {
 var msalConfig =
 {
 auth:
 {
 clientId: '<Client ID [CanvasClientId]>',
 authority: 'https://login.microsoftonline.com/<Directory ID>'
 },
 cache:
 {
 cacheLocation: 'localStorage',
 storeAuthStateInCookie: false
 }
 };
 if (!clientApplication) {
 clientApplication = new Msal.UserAgentApplication(msalConfig);
 }
 }());
 </script>
</head>


<body>
 <script>
 function getOAuthCardResourceUri(activity) {
 if (activity &&
 activity.attachments &&
 activity.attachments[0] &&
 activity.attachments[0].contentType === 'application/vnd.microsoft.card.oauth' &&
 activity.attachments[0].content.tokenExchangeResource) {
 // asking for token exchange with AAD
 return activity.attachments[0].content.tokenExchangeResource.uri;
 }
 }

 function exchangeTokenAsync(resourceUri) {
 let user = clientApplication.getAccount();
 if (user) {
 let requestObj = {
 scopes: [resourceUri]
 };
 return clientApplication.acquireTokenSilent(requestObj)
 .then(function (tokenResponse) {
 return tokenResponse.accessToken;
 })
 .catch(function (error) {
 console.log(error);
 });
 }
 else {
 return Promise.resolve(null);
 }
 }
 </script>
 <script>

 (async function main() {

 // Add your BOT ID below
 var BOT_ID = "<BOT ID>";
 var theURL = "https://powerva.microsoft.com/api/botmanagement/v1/directline/directlinetoken?botId=" + BOT_ID;

 const { token } = await fetchJSON(theURL);
 const directLine = window.WebChat.createDirectLine({ token });
 var userID = clientApplication.account?.accountIdentifier != null ? ("Your-customized-prefix-max-20-characters" + clientApplication.account.accountIdentifier).substr(0,64) : (Math.random().toString() + Date.now().toString().substr(0,64) // Make sure this will not exceed 64 characters 
 const store = WebChat.createStore({}, ({ dispatch }) => next => action => {
 const { type } = action;
 if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
 dispatch({
 type: 'WEB_CHAT/SEND_EVENT',
 payload: {
 name: 'startConversation',
 type: 'event',
 value: { text: "hello" }
 }
 });
 return next(action);
 }
 if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
 const activity = action.payload.activity;
 let resourceUri;
 if (activity.from && activity.from.role === 'bot' &&
 (resourceUri = getOAuthCardResourceUri(activity))) {
 exchangeTokenAsync(resourceUri).then(function (token) {
 if (token) {
 directLine.postActivity({
 type: 'invoke',
 name: 'signin/tokenExchange',
 value: {
 id: activity.attachments[0].content.tokenExchangeResource.id,
 connectionName: activity.attachments[0].content.connectionName,
 token
 },
 "from":{
 id:userId, 
 name:clientApplication.account.userName,
 role:"user"
 }
 }).subscribe(
 id => {
 return next(action);
 });
 const styleOptions = {

 //Add styleOptions to customize Web Chat canvas
 hideUploadButton: true
 };

 window.WebChat.renderWebChat(
 {
 directLine: directLine,
 store,
 userID:userId, 
 styleOptions
 },
 document.getElementById('webchat')
 ); 
})().catch(err => console.error("An error occurred: " + err));


 </script>
</body>
</html>

 

 

I am seeing the below errors as in the snapshot: I am using the same code from the document but i have no clue what is going on. wrong.
1.png2.png



Categories:
I have the same question (0)
  • CU22081450-0 Profile Picture
    Most Valuable Professional on at

    Hi @Anonymous ,

     

    Try to add the below scripts inside the HTML file.

    <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <script type="text/javascript" src="https://alcdn.msauth.net/lib/1.2.0/js/msal.js"></script>
    <script src="https://unpkg.com/@azure/storage-blob@10.3.0/browser/azure-storage.blob.min.js"
    integrity="sha384-fsfhtLyVQo3L3Bh73qgQoRR328xEeXnRGdoi53kjo1uectCfAHFfavrBBN2Nkbdf"
    crossorigin="anonymous"></script>
    <script type="text/javascript">
    if (typeof Msal === 'undefined') document.write(unescape("%3Cscript src='https://alcdn.msftauth.net/lib/1.2.0/js/msal.js' type='text/javascript' %3E%3C/script%3E"));
    </script>

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @renatoromao ,

    On adding the code with reference to the github doc code provided. I no longer see the MSAL error,Thanks. But the syntax error still persist on the below code.

     var userID = clientApplication.account?.accountIdentifier != null ? ("mypva" + clientApplication.account.accountIdentifier).substr(0,64) : (Math.random().toString() + Date.now().toString().substr(0,64);
     

    Error log from chrome console: Uncaught SyntaxError: Unexpected token '.'

     

    Regards,

    Hemanth

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Copilot Studio

#1
Valantis Profile Picture

Valantis 802

#2
Vish WR Profile Picture

Vish WR 331

#3
Haque Profile Picture

Haque 292

Last 30 days Overall leaderboard