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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.