Forum Discussion

vcima's avatar
vcima
Brass Contributor
Mar 23, 2020

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

 

 

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

    • vcima's avatar
      vcima
      Brass Contributor

      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);
      }
      }); 

       

      • vcima's avatar
        vcima
        Brass Contributor

        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

Resources