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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.