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
Giampaolo
New Member

OAuth2 grant type authorization code

Hi All, 

i'm trying to implement the OAuth2 authentication in a custom connector

the first time i run the connector it asks for username and password and then it asks for the authorization from the registered app, the second time i rerun the connector i'm not asked anymore the username and password but i'm asked only to approve the authorization for the registered app

how can i do to force the connector to ask me for username and password everytime i run the connector?

 

this is the code i user

demo = [
TestConnection = (dataSourcePath) => {"demo.Contents", dataSourcePath},
Authentication = [
OAuth = [
StartLogin = StartLogin,
FinishLogin = FinishLogin,
Label = Extension.LoadString("DataSourceLabel")
]
]
// Label = Extension.LoadString("DataSourceLabel")
];

 

StartLogin = (resourceUrl, state, display) =>
let
AuthorizeUrl = "https://[servername]/[tenant]/as/authorization.oauth2?" & Uri.BuildQueryString([
client_id = client_id,
response_type = "code",
// state = state,
redirect_uri = redirect_uri])

in
[
LoginUri = AuthorizeUrl,
CallbackUri = redirect_uri,
WindowHeight = windowHeight,
WindowWidth = windowWidth,
Context = null
];

FinishLogin = (context, callbackUri, state) =>
let
Parts = Uri.Parts(callbackUri)[Query]
in
TokenMethod(Parts[code]);

TokenMethod = (code) =>
let

Response = Web.Contents(" https://[servername]/[tenant]/as/token.oauth2", [
Content = Text.ToBinary(Uri.BuildQueryString([
client_id = client_id,
client_secret = client_secret,
code = code,
grant_type = "authorization_code",
redirect_uri = redirect_uri])),
IsRetry = true,
Headers=[#"Content-type" = "application/x-www-form-urlencoded",#"Accept" = "application/json"]]),
Parts = Json.Document(Response)
in
Parts;

 

 

 

0 REPLIES 0

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.