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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.