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
FrederikB
Frequent Visitor

Refreshing jwt?

I am building a custom connector.

All requests require a jwt, which expires after 15 minutes.

 

I get a jwt by calling a /login endpoint. I am able to get the token, and make the requests, but can't enable automatic refreshes. Tried following a tutorial, but it does not work. 

 

I am pretty sure it is because I don't tell PBI how to get the new token on refresh.


query.pq

 

 

let
    result = Youandx_v2.Contents()
in
    result

 

 

 

.pq file, where I declare the "TestConnection", where I think something is wrong. Should I instead do something with my getJwt function?

 

 

Youandx_v2 = [
    TestConnection = (dataSourcePath) => { "Youandx.Contents" },
    Authentication = [
        UsernamePassword = [
            UsernameLabel = "Username",
            PasswordLabel = "Password"
        ]
    ],
    Label = Extension.LoadString("DataSourceLabel")
];

 

 

 

 

Another place in same file:

 

 

[DataSource.Kind="Youandx_v2", Publish="Youandx_v2.Publish"]
shared Youandx_v2.Contents = () =>
    let
        jwt = getJwt(),
        navTable = navTable(jwt)
    in
        navTable;

 

 

 

navTable function

 

 

navTable = (jwt as text) as table => 
    let 
        bookingTable = getBookings(jwt),
        source = #table({"Name", "Data", "ItemKind", "ItemName", "IsLeaf"}, {
            {"Bookings", bookingTable, "Table", "Table", true},
            {"Speakers", getSpeakers(jwt), "Table", "Table", true} ,
            {"Products", getProducts(jwt), "Table", "Table", true},
            {"Invoices", getInvoices(bookingTable), "Table", "Table", true}, 
            {"Line Items", getLineItems(bookingTable), "Table", "Table", true}, 
            {"Plans", getPlans(jwt), "Table", "Table", true},
            {"Speaker Account", getSpeakerAccounts(jwt), "Table", "Table", true}
        }),
        navTable = Table.ToNavigationTable(source, {"Name"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
    in
        navTable;

 

 

 

getJwt

 

 

getJwt = () => 
    let 
        username = Extension.CurrentCredential()[Username],
        password = Extension.CurrentCredential()[Password],
        URL = "https://www.youandx.com/api/v1/login",
        headers = [
            #"Content-Type"="application/json"
        ],
        bodyData = Json.FromValue([tmode = 2, hold = 0, email = username, password = password]),
        web = Web.Contents(URL, [ Content = bodyData, Headers = headers, ManualStatusHandling = {404, 400}]),
        result = Json.Document(web),
        first = Record.ToTable(result),
        Value = first{1}[Value],
        jwt = Value[jwt]
    in
        jwt;

 

 

 

As you can see, I get a jwt, and pass it on to navTable and then each of the functions, for example getBookings. But how do I make sure, that the getJwt function is called upon refresh?

Thanks.

 

EDIT: This is the message I get in the Power BI Web interface when trying to refresh the data: "Unable to refresh the model (id=3228545) because it references an unsupported data source."

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @FrederikB ,

 

Please try below code to decode JWT token in custom connector.

let
    Token = "<snip>",
    Base64Url.Decode = (s) => Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") & {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
    Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
    Parts

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @FrederikB ,

 

Please try below code to decode JWT token in custom connector.

let
    Token = "<snip>",
    Base64Url.Decode = (s) => Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") & {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
    Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
    Parts

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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.