SOLVED

How can I auto-logged an user inside a Sharepoint Web Part?

Brass Contributor

diagram.jpg

 

 

I have a website "Play web". When I want to access into this site I have to login previously with user/pass. An authtentication module, handle this info and starts a communication with an Azure AD. If the user is validated properly using a callback the control is returned to the Play Web with the user logged. All these steps works fine.


Where is the problem?. One of our clients wants to embed this "Play web" inside his Sharepoint but he doesn't want relogin. He needs to use the Sharepoint context to autologged the user into the website.  

 

Is there any way to do this?,  Should have I setup something in Azure AD: Proxy, Function?

 

I'm stuck with this.

 

Regards

3 Replies
best response confirmed by vcima (Brass Contributor)
Solution
Hi,
You can try using Microsoft Authentication Library (MSAL). Please refer the below link
https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-overview

Hope it helps, please like it or mark it as a solution if it resolves ur clarification or issue
-Sudharsan K...

@Sudharsan K 

 

Hi!, I have solve the problem with this:

 

import {UserAgentApplication} from "msal";

const
config = {
auth: {
clientId: "client-id",
authority: "https://login.microsoftonline.com/tenant-id"
}
};

const myMSALObj = new UserAgentApplication(config);

let
accessTokenRequest = {
scopes: ["user.read"],
loginHint: this.context.pageContext.user.loginName,
extraQueryParameters: {domain_hint: 'organizations'}
}

myMSALObj.acquireTokenSilent(accessTokenRequest).then(function(accessTokenResponse) {
// Acquire token silent success
// call API with token
let accessToken = accessTokenResponse.accessToken;
let scopes = accessTokenResponse.scopes;
}).catch(function (error) {
//Acquire token silent failure, and send an interactive request
console.log(error);
if (error.errorMessage.indexOf("interaction_required") !== -1) {
myMSALObj.acquireTokenRedirect(accessTokenRequest);
}
}); 

 

Hi @Sudharsan K 


I have a problem with this accessToken. When I try to validate, something goes wrong:  The Token's Signature resulted invalid when verified using the Algorithm: SHA256withRSA

Do you know what can I do to validate the Azure AD Token?


Regards

1 best response

Accepted Solutions
best response confirmed by vcima (Brass Contributor)
Solution
Hi,
You can try using Microsoft Authentication Library (MSAL). Please refer the below link
https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-overview

Hope it helps, please like it or mark it as a solution if it resolves ur clarification or issue
-Sudharsan K...

View solution in original post