Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Yaostha
Helper II
Helper II

SSO to powerBI REST API from Azure Web App or SharePoint Provider Hosted Add In

Hi,

   I am accessing the powerBI dashboards and reports using REST API calls. My application will be Azure Web App or SharePoint provider hosted add in with Azure AD authentication enabled.

  I need to authenticate user credentials to poewrBI REST API without additional popup. User will login to webapp/sharepoint addin and further they shouldn't be prompted for login.

 

At present I am using this code to authenticate user which pops for user name and password.

 

protected void signInButton_Click(object sender, EventArgs e)
{
//Create a query string
//Create a sign-in NameValueCollection for query string
var @params = new NameValueCollection
{
//Azure AD will return an authorization code.
//See the Redirect class to see how "code" is used to AcquireTokenByAuthorizationCode
{"response_type", "code"},

//Client ID is used by the application to identify themselves to the users that they are requesting permissions from.
//You get the client id when you register your Azure app.
{"client_id", Properties.Settings.Default.ClientID},

//Resource uri to the Power BI resource to be authorized
{"resource", Properties.Settings.Default.PowerBiAPI},

//After user authenticates, Azure AD will redirect back to the web app
{"redirect_uri", "http://localhost:13526/Redirect"}
};

//Create sign-in query string
var queryString = HttpUtility.ParseQueryString(string.Empty);
queryString.Add(@params);

//Redirect authority
//Authority Uri is an Azure resource that takes a client id to get an Access token
string authorityUri = Properties.Settings.Default.AADAuthoritySignInUri;
var authUri = String.Format("{0}?{1}", authorityUri, queryString);
Response.Redirect(authUri);
}

 

Regards,

Yasotha

2 REPLIES 2
Eric_Zhang
Employee
Employee

@Yaostha

I don't know too much about SSO, however per my understanding, it is more some configuration in Sharepoint side, see Setup SharePoint Online & On-Premises Single-Sign-on (SSO). You can't just avoid such "multiple logins" in C# code.

Hi,

   Thanks. But I am looking for SSO to Power BI.

 

Regards,

Yasotha

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.