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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bnobo
Frequent Visitor

Charset issue with Basic authentication

Hi,

 

I'm using PowerQuery as a datasource for an Excel worksheet. Data are exposed by a REST API supporting Basic Authentication. It is working well except when user name or password contains special characters like µ or é. It seems PowerQuery converts the provided "user:password" to US-ASCII during Basic authentication instead of using UTF-8. Spécial characters like µ and é are replaced with a "?" (char code 0x3F). Below is a Wireshark capture where I tried "µéè" as password and we can see it became "???":

 

bnobo_0-1634132625284.png

 

I tried to add a "WWW-Authenticate" header on the 401 response with charset="UTF-8" in value like specified in the RFC : https://www.rfc-editor.org/rfc/rfc7617#section-2.1

 

WWW-Authenticate: Basic realm="simple", charset="UTF-8"

 

But it seems PowerQuery simply ignores this header because no more query is emitted after the first 401 Unauthorized.

 

I can workaround the problem using Anonymous authentication and providing the header manually:

 

 

 

 

let
    Auth = User & ":" & Password,
    Bytes = Text.ToBinary(Auth),
    Credentials = Binary.ToText(Bytes, BinaryEncoding.Base64),
    Source = Web.Contents("http://localhost:53671/7bc0cca0-f3ae-49ce-a229-d9daa0941103/TestBasicAuthentication/Get",    
    [
      Headers = [#"Authorization" = "Basic " & Credentials]
    ])
in
    Source

 

 

 

This solution works well but it is a security issue because the password would be exposed in clear text in the Excel file.

 

Is it possible to force Basic authentication to use UTF-8 encoding ?

1 ACCEPTED SOLUTION
Ehren
Microsoft Employee
Microsoft Employee

At a high level, the answer is "whenever your Excel channel gets the December release of Power Query". There are more details in the below thread about how to determine which release channel you're on (which determines how quickly you'll receive PQ updates), and how to determine which version of PQ you have.

 

https://social.technet.microsoft.com/Forums/en-US/496325f1-bad0-49fd-a293-be654ccaf67d/power-query-v...

View solution in original post

9 REPLIES 9
v-eqin-msft
Community Support
Community Support

Hi @bnobo ,

 

According to the syntax of Text.ToBinary():

Eyelyn9_0-1634697663935.png

The second parameter is optional encoding where you may try UTF-8

 

May help:

https://seddryck.wordpress.com/2017/06/22/encoding-basic-authentication-in-an-url/

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This issue is not related to M language but occurs when using the built-in Basic auth. Please read @Ehren message and following bellow

Ehren
Microsoft Employee
Microsoft Employee

Hi @bnobo . Just to confirm: the issue occurs when using the built-in Basic auth, not passing the creds manually via custom M. Is that correct?

bnobo
Frequent Visitor

Hi @Ehren , you are right, the issue occurs when using the built-in Basic auth. 

Ehren
Microsoft Employee
Microsoft Employee

Ok. Let me see if there's a way to solve this without breaking backwards-compatibility.

bnobo
Frequent Visitor

You could handle the "charset" auth-param returned by the server in WWW-Authenticate header when the authentication fail (401 status code) as stated in Basic Authentication RFC  7617: https://datatracker.ietf.org/doc/html/rfc7617#section-2.1

 

If the WWW-Authenticate header returned by the server contains 'charset="UTF-8"' then re-encode username:password with UTF-8 encoding and re-emit the request.

Doing so, the encoding would change only for servers requesting UTF-8 encoding.

Ehren
Microsoft Employee
Microsoft Employee

Because UTF-8 encoding for ASCII characters is identical to ASCII encoding, it should be safe to always encode with UTF-8. The only existing case this would "break" would be non-ASCII characters that today are being mapped to "?", but if anyone is depending on that behavior they can simply use "?" in their username/password instead.

 

The fix should be available in the December release of PBIDesktop.

bnobo
Frequent Visitor

When the fix will be available for Microsoft Excel ?

Ehren
Microsoft Employee
Microsoft Employee

At a high level, the answer is "whenever your Excel channel gets the December release of Power Query". There are more details in the below thread about how to determine which release channel you're on (which determines how quickly you'll receive PQ updates), and how to determine which version of PQ you have.

 

https://social.technet.microsoft.com/Forums/en-US/496325f1-bad0-49fd-a293-be654ccaf67d/power-query-v...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.