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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
zzinoun
Resolver I
Resolver I

Custom Connector Issue (mez file)

Hi ,

 

I am trying to use a custom connector to set up an automatoc refresh. However, I am stuck at this issue :

zzinoun_0-1687967318258.png

 

I guess this comes from a wrong parameter in the connector code but I could not determine the wrong part.

 

Here is the connector I am using (mez file).

 

section ProjectInsights;

[DataSource.Kind="ProjectInsights", Publish="ProjectInsights.Publish"]
shared ProjectInsights.Contents = (ProjectId as text) =>
let
    source = OData.Feed(
        Extension.LoadString("ProjectInsightsFeed") & ProjectId,
        null,
        [ ODataVersion = 4, MoreColumns = true ]
    )
in
    source;
openidConfiguration = Json.Document(Web.Contents(Extension.LoadString("WellKnown")));
ProjectInsights = [
    Authentication = [
        OAuth = [
            StartLogin = StartLogin,
            FinishLogin = FinishLogin,
            Label = "Bentley Account"
        ]
    ],
    Label = Extension.LoadString("DataSourceLabel")
];
client_id = Extension.LoadString("ClientId");
windowWidth = 600;
windowHeight = 600;
code_challenge = Binary.ToText(Text.ToBinary(Text.NewGuid()), BinaryEncoding.Base64);
StartLogin = (resourceUrl, state, display) =>
let
    qs = Uri.BuildQueryString([
        client_id = client_id,
        state = state,
        response_type = "code",
        scope=Extension.LoadString("Scope"),
        code_challenge = code_challenge,
        redirect_uri = redirect_uri
    ]),
    AuthorizeUrl = openidConfiguration[authorization_endpoint] & "?" & qs
in
    [
        LoginUri = AuthorizeUrl,
        CallbackUri = redirect_uri,
        WindowHeight = windowHeight,
        WindowWidth = windowWidth,
        Context = null
    ];

FinishLogin = (context, callbackUri, state) =>
let
    parts = Uri.Parts(callbackUri)[Query],
    result = if (Record.HasFields(parts, {"error", "error_description"}))
        then
            error Error.Record(parts[error], parts[error_description], parts)
        else
            TokenMethod("authorization_code", parts[code])
in
    result;
TokenMethod = (grantType, code) =>
let
    query = [
        client_id = client_id,
        code = code,
        grant_type = "authorization_code",
        code_verifier = code_challenge,
        redirect_uri = redirect_uri
    ],
    queryWithCode = if (grantType = "refresh_token") then [ refresh_token = code ] else [code = code],
    Response = Web.Contents(
        openidConfiguration[token_endpoint],
        [
            Content = Text.ToBinary(Uri.BuildQueryString(query & queryWithCode)),
            Headers = [
                #"Content-type" = "application/x-www-form-urlencoded",
                #"Accept" = "application/json"
            ],
            ManualStatusHandling = { 400 }
        ]
    ),
    Parts = Json.Document(Response),
    Result =
        if (Record.HasFields(Parts, {"error", "error_description"}))
            then
                error Error.Record(Parts[error], Parts[error_description], Parts)
            else
                Parts
in
    Result;
Refresh = (resourceUrl, refresh_token) => TokenMethod("refresh_token", refresh_token);
 
 
Could you please advise  ?
 
Thank you,
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.