Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Copilot Studio - General
Unanswered

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

(0) ShareShare
ReportReport
Posted on by

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:
  • Community Power Platform Member Profile Picture
    on at
    Re: How to configure Single Sign On in PVA with Sharepoint and Teams?

    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

  • CU22081450-0 Profile Picture
    Most Valuable Professional on at
    Re: How to configure Single Sign On in PVA with Sharepoint and Teams?

    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>

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Copilot Studio - General

#1
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 25

#1
Pablo Roldan Profile Picture

Pablo Roldan 25

#3
stampcoin Profile Picture

stampcoin 10

Overall leaderboard