[{"data":1,"prerenderedAt":643},["ShallowReactive",2],{"navigation_docs":3,"-concepts-token-refresh":189,"-concepts-token-refresh-surround":638},[4,30,65,105,120,135,164,184],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting started",false,"/getting-started","1.getting-started",[10,15,20,25],{"title":11,"path":12,"stem":13,"icon":14},"Introduction","/getting-started/introduction","1.getting-started/1.introduction","i-lucide-book-open",{"title":16,"path":17,"stem":18,"icon":19},"Installation","/getting-started/installation","1.getting-started/2.installation","i-lucide-download",{"title":21,"path":22,"stem":23,"icon":24},"Quick start","/getting-started/quick-start","1.getting-started/3.quick-start","i-lucide-rocket",{"title":26,"path":27,"stem":28,"icon":29},"Session Lab","/getting-started/session-lab","1.getting-started/4.session-lab","i-lucide-flask-conical",{"title":31,"icon":6,"path":32,"stem":33,"children":34,"page":6},"Concepts","/concepts","2.concepts",[35,40,45,50,55,60],{"title":36,"path":37,"stem":38,"icon":39},"How it works","/concepts/how-it-works","2.concepts/1.how-it-works","i-lucide-workflow",{"title":41,"path":42,"stem":43,"icon":44},"Sessions and tokens","/concepts/sessions-and-tokens","2.concepts/2.sessions-and-tokens","i-lucide-key-round",{"title":46,"path":47,"stem":48,"icon":49},"State and events","/concepts/state-and-events","2.concepts/3.state-and-events","i-lucide-radio",{"title":51,"path":52,"stem":53,"icon":54},"Token refresh","/concepts/token-refresh","2.concepts/4.token-refresh","i-lucide-refresh-cw",{"title":56,"path":57,"stem":58,"icon":59},"Storage","/concepts/storage","2.concepts/5.storage","i-lucide-hard-drive",{"title":61,"path":62,"stem":63,"icon":64},"Guarantees","/concepts/guarantees","2.concepts/6.guarantees","i-lucide-shield-check",{"title":66,"icon":6,"path":67,"stem":68,"children":69,"page":6},"Providers","/providers","3.providers",[70,75,80,85,90,95,100],{"title":71,"path":72,"stem":73,"icon":74},"Choosing a provider","/providers/choosing","3.providers/1.choosing","i-lucide-signpost",{"title":76,"path":77,"stem":78,"icon":79},"Credentials","/providers/credentials","3.providers/2.credentials","i-lucide-user-round-key",{"title":81,"path":82,"stem":83,"icon":84},"OAuth 2.0 and OpenID Connect","/providers/oauth2","3.providers/3.oauth2","i-lucide-shield",{"title":86,"path":87,"stem":88,"icon":89},"OAuth through your backend","/providers/backend-oauth","3.providers/4.backend-oauth","i-lucide-server",{"title":91,"path":92,"stem":93,"icon":94},"Google","/providers/google","3.providers/5.google","i-simple-icons-google",{"title":96,"path":97,"stem":98,"icon":99},"Apple","/providers/apple","3.providers/6.apple","i-simple-icons-apple",{"title":101,"path":102,"stem":103,"icon":104},"Custom providers","/providers/custom","3.providers/7.custom","i-lucide-puzzle",{"title":106,"icon":6,"path":107,"stem":108,"children":109,"page":6},"Flutter","/flutter","4.flutter",[110,115],{"title":111,"path":112,"stem":113,"icon":114},"Widgets","/flutter/widgets","4.flutter/1.widgets","i-lucide-layout-template",{"title":116,"path":117,"stem":118,"icon":119},"Routing","/flutter/routing","4.flutter/2.routing","i-lucide-route",{"title":121,"icon":6,"path":122,"stem":123,"children":124,"page":6},"HTTP","/http","5.http",[125,130],{"title":126,"path":127,"stem":128,"icon":129},"Dio","/http/dio","5.http/1.dio","i-lucide-arrow-left-right",{"title":131,"path":132,"stem":133,"icon":134},"Other HTTP clients","/http/other-clients","5.http/2.other-clients","i-lucide-plug-zap",{"title":136,"icon":6,"path":137,"stem":138,"children":139,"page":6},"Guides","/guides","6.guides",[140,145,150,155,159],{"title":141,"path":142,"stem":143,"icon":144},"Multiple accounts","/guides/multi-account","6.guides/1.multi-account","i-lucide-users",{"title":146,"path":147,"stem":148,"icon":149},"Sign-out and revocation","/guides/sign-out","6.guides/2.sign-out","i-lucide-log-out",{"title":151,"path":152,"stem":153,"icon":154},"Access policy","/guides/access-policy","6.guides/3.access-policy","i-lucide-shield-alert",{"title":156,"path":157,"stem":158,"icon":29},"Testing","/guides/testing","6.guides/4.testing",{"title":160,"path":161,"stem":162,"icon":163},"Backend requirements","/guides/backend-requirements","6.guides/5.backend-requirements","i-lucide-server-cog",{"title":165,"icon":6,"path":166,"stem":167,"children":168,"page":6},"Reference","/reference","7.reference",[169,174,179],{"title":170,"path":171,"stem":172,"icon":173},"API reference","/reference/api","7.reference/1.api","i-lucide-library",{"title":175,"path":176,"stem":177,"icon":178},"FAQ","/reference/faq","7.reference/2.faq","i-lucide-message-circle-question",{"title":180,"path":181,"stem":182,"icon":183},"Troubleshooting","/reference/troubleshooting","7.reference/3.troubleshooting","i-lucide-wrench",{"title":185,"path":186,"stem":187,"icon":188},"Changelog","/changelog","changelog","i-lucide-history",{"id":190,"title":51,"body":191,"description":631,"extension":632,"links":633,"meta":634,"navigation":635,"path":52,"seo":636,"stem":53,"__hash__":637},"docs/2.concepts/4.token-refresh.md",{"type":192,"value":193,"toc":624},"minimark",[194,199,332,336,340,353,360,370,374,384,387,416,419,433,458,466,470,477,481,607,620],[195,196,198],"h2",{"id":197},"when-a-refresh-happens","When a refresh happens",[200,201,202,218],"table",{},[203,204,205],"thead",{},[206,207,208,212,215],"tr",{},[209,210,211],"th",{},"Trigger",[209,213,214],{},"Applies to",[209,216,217],{},"Details",[219,220,221,244,263,282,301,317],"tbody",{},[206,222,223,230,233],{},[224,225,226],"td",{},[227,228,229],"strong",{},"Scheduled",[224,231,232],{},"The active session",[224,234,235,239,240,243],{},[236,237,238],"code",{},"refreshThreshold"," (60 s by default) before the access token expires. Disable with ",[236,241,242],{},"AuthyraConfig(autoRefresh: false)",".",[206,245,246,251,254],{},[224,247,248],{},[227,249,250],{},"On demand",[224,252,253],{},"Any session",[224,255,256,259,260,262],{},[236,257,258],{},"accessToken()"," refreshes first when the token is within ",[236,261,238],{}," of its expiry.",[206,264,265,270,272],{},[224,266,267],{},[227,268,269],{},"After a 401",[224,271,253],{},[224,273,274,277,278,281],{},[236,275,276],{},"accessToken(rejectedToken: token)"," refreshes even if the token looks valid. ",[236,279,280],{},"authyra_dio"," does this for you.",[206,283,284,289,291],{},[224,285,286],{},[227,287,288],{},"Back in the foreground",[224,290,232],{},[224,292,293,296,297,300],{},[236,294,295],{},"refreshIfNeeded()",", called by ",[236,298,299],{},"AuthyraScope",": timers do not run while a mobile app is suspended.",[206,302,303,308,310],{},[224,304,305],{},[227,306,307],{},"Refresh token deadline",[224,309,232],{},[224,311,312,313,316],{},"When your backend gives ",[236,314,315],{},"refreshTokenExpiresAt"," and refreshing extends it, Authyra refreshes before that deadline so an idle app keeps its session.",[206,318,319,324,326],{},[224,320,321],{},[227,322,323],{},"Explicitly",[224,325,253],{},[224,327,328,331],{},[236,329,330],{},"authyra.refresh()"," refreshes now, for example after changing the user's role server-side.",[195,333,335],{"id":334},"one-refresh-at-a-time","One refresh at a time",[337,338,339],"p",{},"Every trigger goes through one coordinator, which runs at most one refresh per session:",[341,342,343,347,350],"ul",{},[344,345,346],"li",{},"Callers that need a refresh while one is in flight wait for it and get its result.",[344,348,349],{},"The refresh always uses the latest refresh token.",[344,351,352],{},"A caller holding a token that was already replaced gets the new token without a second refresh.",[337,354,355,356,359],{},"That is what makes ",[227,357,358],{},"rotating refresh tokens"," safe. A server that issues a new refresh token on every refresh, and treats reuse of an old one as theft, never sees the same token twice from your app.",[361,362,368],"pre",{"className":363,"code":365,"language":366,"meta":367},[364],"language-text","request A ─ 401 ─┐\nrequest B ─ 401 ─┼─▶ one refresh ─▶ new tokens ─▶ A, B and C retry\nrequest C ─ 401 ─┘\n","text","",[236,369,365],{"__ignoreMap":367},[195,371,373],{"id":372},"what-ends-a-session","What ends a session",[337,375,376,377,380,381,243],{},"A session that can be refreshed ends in one case only: the provider throws ",[236,378,379],{},"RefreshRevokedException",", meaning the server definitively rejected the refresh token. The session is removed with ",[236,382,383],{},"SessionEndReason.revoked",[337,385,386],{},"A session that cannot be refreshed (its provider does not support refresh, it holds no refresh token, or its refresh token has expired) ends as soon as its access token is unusable:",[341,388,389,403],{},[344,390,391,392,395,396,399,400,402],{},"when the server rejects it (a 401 handled by ",[236,393,394],{},"AuthyraInterceptor",", or ",[236,397,398],{},"accessToken(rejectedToken:)","), with ",[236,401,383],{},";",[344,404,405,406,409,410,412,413,243],{},"when it expires, with ",[236,407,408],{},"SessionEndReason.expired",": at startup, on a scheduled check, on ",[236,411,258],{}," or on ",[236,414,415],{},"switchTo",[337,417,418],{},"For a session that can be refreshed, every other failure is transient and keeps the session:",[341,420,421,424,427,430],{},[344,422,423],{},"network errors and timeouts,",[344,425,426],{},"5xx responses,",[344,428,429],{},"a 403 from a proxy or firewall,",[344,431,432],{},"anything else your provider throws.",[337,434,435,436,439,440,443,444,447,448,450,451,453,454,457],{},"A failed scheduled refresh emits ",[236,437,438],{},"SessionRefreshFailedEvent"," and is retried with exponential backoff: ",[236,441,442],{},"retryDelay"," (5 s by default), doubling up to ",[236,445,446],{},"maxRetryDelay"," (5 min). If the access token is still valid, ",[236,449,258],{}," returns it; once it has expired, ",[236,452,258],{}," throws ",[236,455,456],{},"TokenRefreshException"," and the session waits for the network to return.",[459,460,461,462,465],"warning",{},"Map responses carefully in your provider. A refresh endpoint answering 401 or ",[236,463,464],{},"invalid_grant"," means revoked. A 500, a timeout or a captive portal page does not.",[195,467,469],{"id":468},"rotated-tokens-and-storage","Rotated tokens and storage",[337,471,472,473,476],{},"New tokens are persisted before they are used. If the write fails (a full disk, a locked keychain), the new tokens are kept in memory anyway, because the old refresh token is already consumed on the server, and written again with backoff until it succeeds. ",[236,474,475],{},"dispose()"," waits for that write.",[195,478,480],{"id":479},"configuration","Configuration",[361,482,486],{"className":483,"code":484,"language":485,"meta":367,"style":367},"language-dart shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","const AuthyraConfig(\n  autoRefresh: true,                          // Scheduled refresh of the active session.\n  refreshThreshold: Duration(seconds: 60),    // How early a token is considered due.\n  retryDelay: Duration(seconds: 5),           // First retry after a transient failure.\n  maxRetryDelay: Duration(minutes: 5),        // Backoff ceiling.\n);\n","dart",[236,487,488,505,522,551,575,599],{"__ignoreMap":367},[489,490,493,497,501],"span",{"class":491,"line":492},"line",1,[489,494,496],{"class":495},"spNyl","const",[489,498,500],{"class":499},"sBMFI"," AuthyraConfig",[489,502,504],{"class":503},"sTEyZ","(\n",[489,506,508,511,515,518],{"class":491,"line":507},2,[489,509,510],{"class":503},"  autoRefresh",[489,512,514],{"class":513},"sMK4o",":",[489,516,517],{"class":513}," true,",[489,519,521],{"class":520},"sHwdD","                          // Scheduled refresh of the active session.\n",[489,523,525,528,530,533,536,538,542,545,548],{"class":491,"line":524},3,[489,526,527],{"class":503},"  refreshThreshold",[489,529,514],{"class":513},[489,531,532],{"class":499}," Duration",[489,534,535],{"class":503},"(seconds",[489,537,514],{"class":513},[489,539,541],{"class":540},"sbssI"," 60",[489,543,544],{"class":503},")",[489,546,547],{"class":513},",",[489,549,550],{"class":520},"    // How early a token is considered due.\n",[489,552,554,557,559,561,563,565,568,570,572],{"class":491,"line":553},4,[489,555,556],{"class":503},"  retryDelay",[489,558,514],{"class":513},[489,560,532],{"class":499},[489,562,535],{"class":503},[489,564,514],{"class":513},[489,566,567],{"class":540}," 5",[489,569,544],{"class":503},[489,571,547],{"class":513},[489,573,574],{"class":520},"           // First retry after a transient failure.\n",[489,576,578,581,583,585,588,590,592,594,596],{"class":491,"line":577},5,[489,579,580],{"class":503},"  maxRetryDelay",[489,582,514],{"class":513},[489,584,532],{"class":499},[489,586,587],{"class":503},"(minutes",[489,589,514],{"class":513},[489,591,567],{"class":540},[489,593,544],{"class":503},[489,595,547],{"class":513},[489,597,598],{"class":520},"        // Backoff ceiling.\n",[489,600,602,604],{"class":491,"line":601},6,[489,603,544],{"class":503},[489,605,606],{"class":513},";\n",[337,608,609,610,612,613,616,617,243],{},"Invalid values, such as a zero ",[236,611,442],{}," that would spin while offline, make the ",[236,614,615],{},"Authyra"," constructor throw ",[236,618,619],{},"AuthConfigException",[621,622,623],"style",{},"html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":367,"searchDepth":507,"depth":507,"links":625},[626,627,628,629,630],{"id":197,"depth":507,"text":198},{"id":334,"depth":507,"text":335},{"id":372,"depth":507,"text":373},{"id":468,"depth":507,"text":469},{"id":479,"depth":507,"text":480},"When Authyra refreshes, why there is never more than one refresh per session, and how failures are handled.","md",null,{},{"icon":54},{"title":51,"description":631},"VKBBCem-4m41mW0Us-ZZ2hiqWDGbktbxcKaphi5NcEY",[639,641],{"title":46,"path":47,"stem":48,"description":640,"icon":49,"children":-1},"The sealed AuthState your UI renders, the events that describe what happened to each session, and the errors Authyra throws.",{"title":56,"path":57,"stem":58,"description":642,"icon":59,"children":-1},"Where sessions are kept, how they survive restarts and failures, and how to plug your own storage.",1794303128106]