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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

OAuth 2.0 ROPC issue(Data Connector)

Hi 

 

I have created a data connectors that uses an Oauth 2.0 flow to connect to our cloud environment. I have used the client_id, username and password in the flow, yet while execution it prompts for sign credentials which shouldn't be the case. Based on the document this is a special error when there is something wrong with the data source kind and path. 

 

[DataSource.Kind = "System" , Publish="System.Publish"]
shared System.Contents = Value.ReplaceType(SystemNavTable, type function (url as Uri.Type) as any);

 

// Oauth Data Source Kind description


System = [
Testconnection = (dataSourcePath) => {"System.Contents"},
Authentication = [
OAuth = [
StartLogin=StartLogin,
FinishLogin=FinishLogin,
Refresh=Refresh,
Logout=Logout
]
],
Label = "System Connector"
];

StartLogin = (resourceUrl, state, display) =>
let
authorizeUrl = authorize_uri & "?" & Uri.BuildQueryString([
client_id = client_id,
redirect_uri = redirect_uri,
state = state,
scope = "offline_access " & GetScopeString(scopes, scope_prefix),
response_type = "code",
response_mode = "query",
login = "login"
])
in
[
LoginUri = authorizeUrl,
CallbackUri = redirect_uri,
WindowHeight = 720,
WindowWidth = 1024,
Context = null
];

FinishLogin = (context, callbackUri, state) => //FinishLogin = (context, CallbackUri, state) =>
let
// parse the full callbackUri, and extract the Query string
parts = Uri.Parts(callbackUri)[Query],
// if the query string contains an "error" field, raise an error
// otherwise call TokenMethod to exchange our code for an access_token
result = if (Record.HasFields(parts, {"error", "error_description"})) then
error Error.Record(parts[error], parts[error_description], parts)
else
TokenMethod("authorization_code", "code", parts[code])
in
result;

Refresh = (resourceUrl, refresh_token) => TokenMethod("refresh_token", "refresh_token", refresh_token);

Logout = (token) => logout_uri;

//This is called when StartLogin() is completed and a redirect occurs.
TokenMethod = (grantType, tokenField, code) =>
let
queryString = [
client_id= "passing the client id value",
scope="openid clientid(value) offline_access",
grant_type="password",
//response_type="token",
username="passing the username value",
password="passing the password value!"
],
queryWithCode = Record.AddField(queryString, tokenField, code),

tokenResponse = Web.Contents(token_uri, [
Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
Headers = [
#"Content-type" = "application/x-www-form-urlencoded",
#"Accept" = "application/json"
],
ManualStatusHandling = {400}
]),
body = Json.Document(tokenResponse),
result = if (Record.HasFields(body, {"error", "error_description"})) then
error Error.Record(body[error], body[error_description], body)
else
body
in
result;

 

As you see, I'm passing the username and password but it still redirects me to the login screen(which again according the microsoft doc is an error). Can someone please advise what is wrong with the above code. 

 

 

 

3 REPLIES 3
dearwatson
Continued Contributor
Continued Contributor

Hi @AsfarP1 Did you ever resolve this? Trying to implement OAuth2 ROPC myself right now.
dax
Community Support
Community Support

Hi @Anonymous , 

I am nor familiar with this part, I suggest youcould @ super users in this forum or open a ticket for this porblem.

Best Regards,
Zoe Zhi

Anonymous
Not applicable

Hi Zoe

 

I can't open a support ticket and I'm not sure what do you mean by " I suggest youcould @ super users in this forum". Do you mean I should tag super users?

 

I've been trying to get through this issue from quite a while. I've checked Microsoft documents and also checked third party blogs but none of it has helped. Hoping someone very much familiar with OAuth data connectors can help. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.