<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Refreshing jwt? in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Refreshing-jwt/m-p/2912093#M39790</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/354900"&gt;@FrederikB&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try below code to d&lt;SPAN&gt;ecode JWT token in custom connector.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Token = "&amp;lt;snip&amp;gt;",
    Base64Url.Decode = (s) =&amp;gt; Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") &amp;amp; {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
    Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
    Parts&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 09:22:09 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-11-17T09:22:09Z</dc:date>
    <item>
      <title>Refreshing jwt?</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Refreshing-jwt/m-p/2909533#M39777</link>
      <description>&lt;P&gt;I am building a custom connector.&lt;/P&gt;&lt;P&gt;All requests require a jwt, which expires after 15 minutes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am pretty sure it is because I don't tell PBI how to get the new token on refresh.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;query.pq&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;let
    result = Youandx_v2.Contents()
in
    result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.pq file, where I declare the "TestConnection", where I think something is wrong. Should I instead do something with my getJwt function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Youandx_v2 = [
    TestConnection = (dataSourcePath) =&amp;gt; { "Youandx.Contents" },
    Authentication = [
        UsernamePassword = [
            UsernameLabel = "Username",
            PasswordLabel = "Password"
        ]
    ],
    Label = Extension.LoadString("DataSourceLabel")
];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another place in same file:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;[DataSource.Kind="Youandx_v2", Publish="Youandx_v2.Publish"]
shared Youandx_v2.Contents = () =&amp;gt;
    let
        jwt = getJwt(),
        navTable = navTable(jwt)
    in
        navTable;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;navTable function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;navTable = (jwt as text) as table =&amp;gt; 
    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;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;getJwt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;getJwt = () =&amp;gt; 
    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;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: This is the message I get in the Power BI Web interface when trying to refresh the data: "&lt;SPAN&gt;Unable to refresh the model (id=3228545) because it references an unsupported data source."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 12:56:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Refreshing-jwt/m-p/2909533#M39777</guid>
      <dc:creator>FrederikB</dc:creator>
      <dc:date>2022-11-16T12:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Refreshing jwt?</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Refreshing-jwt/m-p/2912093#M39790</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/354900"&gt;@FrederikB&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try below code to d&lt;SPAN&gt;ecode JWT token in custom connector.&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Token = "&amp;lt;snip&amp;gt;",
    Base64Url.Decode = (s) =&amp;gt; Binary.FromText(Text.Replace(Text.Replace(s, "-", "+"), "_", "/") &amp;amp; {"", "", "==", "="}{Number.Mod(Text.Length(s), 4)}, BinaryEncoding.Base64),
    Parts = Json.Document(Base64Url.Decode(Text.Split(Token, "."){1}))
in
    Parts&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 09:22:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Refreshing-jwt/m-p/2912093#M39790</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-17T09:22:09Z</dc:date>
    </item>
  </channel>
</rss>

