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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Marco_Iac
Frequent Visitor

OAuth 2.0 Authorization Code flow grant type - PQ API Connection

Hi, i'm tryng to to get Access Token from an OAuth2 Authorization Code flow.

Here the code: "PART 1" work fine and return the Authorization Code, bat "PART 2" don't work and return error.

 

Thanks for help

 

let

// PART 1: Get Authorization Code
Body =
"{
""username"":""<MyUsername>"",
""password"":""<MyPsw>"",
""scope"":[""<SelectedScope>""]
}",

url = "http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/api/login/sso",
GetJson = Json.Document(Web.Contents(url, [Headers=[ContentType="application/json"], Content=Text.ToBinary(Body)])),
AuthorizationCode = GetJson,

// The previous code correctly returns the Authorization Code

// PART 2: Now I try to Get Access Token passing the Authorization Code, the client_id and the client_secret

// Base64 Encoding
a = "<client_id>" & ":" & "<client_secret>",
a2 = Text.ToBinary(a),
a3 = Binary.ToText(a2, BinaryEncoding.Base64),

TokenURL = "http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/oauth2/token/",
Body2 =
"{
""grant_type"": ""authorization_code"",
""code"": """&AuthorizationCode&"""
}",

Source = Web.Contents(TokenURL, [Headers = [ContentType="application/json", Authorization = "Basic "&a3&""], Content = Text.ToBinary(Body2)])

in Source
1 ACCEPTED SOLUTION
Marco_Iac
Frequent Visitor

Solved, the problem was due to an erroneous Base64 Encoding

View solution in original post

2 REPLIES 2
Marco_Iac
Frequent Visitor

Solved, the problem was due to an erroneous Base64 Encoding

v-yingjl
Community Support
Community Support

Hi @Marco_Iac ,

What did the error message show in power query about part2, did it show the authentication error or anything else?

Could you please consider sharing more details about this issue so that members in the community could help you better.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.