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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Build Login form using Power query

Hi Team,

 

I am trying to build a secured role based custom connector which provides list of REST apis with parameters.

 

Before even my connector lists apis, I want to build a login prompt in power bi which asks for url username and password. On hitting this, generates a toke. I want to use this token as a header for my next screen which shows the list of APIS.

 

How to build this loging promt using power query? Please help!

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@ImkeF @dax 

Cracked the solution,

Here's my custom solution:

 

(CRScheme as text, CRHostName as text, CRPort as text, CRusername as text, CRpassword as text, optional swaggerUrl as text) =>
               let 

                   // delcare types

                    // step1: Login to get the auth token

                    body = Text.ToBinary("{""username"":"""& CRusername & """,""password"":"""& CRpassword & """}"),
                    options =   [
                                    Headers = [#"Content-type"="application/json"],
                                    Content = body
                                ],
                    // Build the authentication URL
                    AuthenticationUrl = CRScheme & "://" & CRHostName & ":" & CRPort & AuthenticationBaseUrl,            
                    tokenResonse = Json.Document(Web.Contents(AuthenticationUrl, options)),

                    // step2: Set the access token as part of API request header with additional options

                    DefaultRequestHeader = [
                             #"X-Authorization" =  tokenResonse[token]  // assign the token value obtained from step1
                    ],

Thanks!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@ImkeF @dax 

Cracked the solution,

Here's my custom solution:

 

(CRScheme as text, CRHostName as text, CRPort as text, CRusername as text, CRpassword as text, optional swaggerUrl as text) =>
               let 

                   // delcare types

                    // step1: Login to get the auth token

                    body = Text.ToBinary("{""username"":"""& CRusername & """,""password"":"""& CRpassword & """}"),
                    options =   [
                                    Headers = [#"Content-type"="application/json"],
                                    Content = body
                                ],
                    // Build the authentication URL
                    AuthenticationUrl = CRScheme & "://" & CRHostName & ":" & CRPort & AuthenticationBaseUrl,            
                    tokenResonse = Json.Document(Web.Contents(AuthenticationUrl, options)),

                    // step2: Set the access token as part of API request header with additional options

                    DefaultRequestHeader = [
                             #"X-Authorization" =  tokenResonse[token]  // assign the token value obtained from step1
                    ],

Thanks!

ImkeF
Community Champion
Community Champion

Great @Anonymous   

& thanks for sharing !!

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

dax
Community Support
Community Support

Hi Nagpraveen, 

The login windows is usually show when you connect to source, but it seems that you want to use dynamic credential to get data in API by M code. I am not professional in this part(token part), so I suggest that you could ask @ImkeF for more sugestions.

Best Regards,
Zoe Zhi

ImkeF
Community Champion
Community Champion

Sorry, but I'm not aware of such an option.

You might want to post an issue in the custom connecotr GitHub repository instead: https://github.com/microsoft/DataConnectors 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors