[{"data":1,"prerenderedAt":1795},["ShallowReactive",2],{"navigation":3,"\u002Fguides\u002Foauth-grant-context":237,"\u002Fguides\u002Foauth-grant-context-surround":1790},[4,43,119,127,211],{"title":5,"path":6,"stem":7,"children":8,"icon":42},"Get started","\u002Fgetting-started","1.getting-started\u002F1.index",[9,12,17,22,27,32,37],{"title":10,"path":6,"stem":7,"icon":11},"Introduction","i-lucide-house",{"title":13,"path":14,"stem":15,"icon":16},"Install","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F2.installation","i-lucide-download",{"title":18,"path":19,"stem":20,"icon":21},"Quick start","\u002Fgetting-started\u002Fquick-start","1.getting-started\u002F3.quick-start","i-lucide-play",{"title":23,"path":24,"stem":25,"icon":26},"Choose your setup","\u002Fgetting-started\u002Fchoose-a-sign-in-stack","1.getting-started\u002F4.choose-a-sign-in-stack","i-lucide-signpost",{"title":28,"path":29,"stem":30,"icon":31},"Browser clients","\u002Fgetting-started\u002Fbrowser-clients","1.getting-started\u002F5.browser-clients","i-lucide-globe",{"title":33,"path":34,"stem":35,"icon":36},"Coding agents","\u002Fgetting-started\u002Fai-agents","1.getting-started\u002F6.ai-agents","i-lucide-bot",{"title":38,"path":39,"stem":40,"icon":41},"Upgrade from 3.x","\u002Fgetting-started\u002Fupgrading-to-4","1.getting-started\u002F8.upgrading-to-4","i-lucide-arrow-up-right","i-lucide-rocket",{"title":44,"icon":45,"path":46,"stem":47,"children":48,"page":118},"Guides","i-lucide-waypoints","\u002Fguides","2.guides",[49,54,59,64,69,74,79,84,89,94,99,104,109,114],{"title":50,"path":51,"stem":52,"icon":53},"Register users","\u002Fguides\u002Fregistration","2.guides\u002F02.registration","i-lucide-user-plus",{"title":55,"path":56,"stem":57,"icon":58},"Sign users in","\u002Fguides\u002Fsign-in","2.guides\u002F03.sign-in","i-lucide-log-in",{"title":60,"path":61,"stem":62,"icon":63},"Sign users out","\u002Fguides\u002Fsign-out","2.guides\u002F04.sign-out","i-lucide-log-out",{"title":65,"path":66,"stem":67,"icon":68},"Two-factor auth","\u002Fguides\u002Ftwo-factor","2.guides\u002F05.two-factor","i-lucide-smartphone",{"title":70,"path":71,"stem":72,"icon":73},"Email-code sign-in","\u002Fguides\u002Femail-code","2.guides\u002F06.email-code","i-lucide-mail",{"title":75,"path":76,"stem":77,"icon":78},"Reset a password","\u002Fguides\u002Freset-password","2.guides\u002F07.reset-password","i-lucide-key-round",{"title":80,"path":81,"stem":82,"icon":83},"Manage account","\u002Fguides\u002Fmanage-account","2.guides\u002F08.manage-account","i-lucide-user-cog",{"title":85,"path":86,"stem":87,"icon":88},"Manage passkeys","\u002Fguides\u002Fmanage-passkeys","2.guides\u002F09.manage-passkeys","i-lucide-scan-face",{"title":90,"path":91,"stem":92,"icon":93},"Link accounts","\u002Fguides\u002Flink-external-accounts","2.guides\u002F10.link-external-accounts","i-lucide-link",{"title":95,"path":96,"stem":97,"icon":98},"Require step-up","\u002Fguides\u002Fstep-up","2.guides\u002F11.step-up","i-lucide-shield-check",{"title":100,"path":101,"stem":102,"icon":103},"No public sign-up","\u002Fguides\u002Finternal-app","2.guides\u002F12.internal-app","i-lucide-building-2",{"title":105,"path":106,"stem":107,"icon":108},"List and revoke signed-in sessions","\u002Fguides\u002Factive-sessions","2.guides\u002F13.active-sessions","i-lucide-monitor-smartphone",{"title":110,"path":111,"stem":112,"icon":113},"MCP server with OAuth","\u002Fguides\u002Fmcp-server-oauth","2.guides\u002F14.mcp-server-oauth","i-lucide-plug-zap",{"title":115,"path":116,"stem":117,"icon":103},"Host context on OAuth grants","\u002Fguides\u002Foauth-grant-context","2.guides\u002F15.oauth-grant-context",false,{"title":120,"path":121,"stem":122,"children":123,"icon":126},"Composables","\u002Fcomposables","3.composables\u002F1.index",[124],{"title":125,"path":121,"stem":122,"icon":126},"Build a custom stack","i-lucide-blocks",{"title":128,"icon":129,"path":130,"stem":131,"children":132,"page":118},"Reference","i-lucide-book-open","\u002Fmodules","4.modules",[133,138,142,147,151,156,161,166,170,175,179,184,188,193,198,202,206],{"title":134,"path":135,"stem":136,"icon":137},"Endpoint reference","\u002Fmodules\u002Fendpoints","4.modules\u002F01.endpoints","i-lucide-route",{"title":139,"path":140,"stem":141,"icon":78},"Password auth","\u002Fmodules\u002Fpassword-auth","4.modules\u002F02.password-auth",{"title":143,"path":144,"stem":145,"icon":146},"Composition table","\u002Fmodules\u002Fcomposition","4.modules\u002F03.composition","i-lucide-table",{"title":148,"path":149,"stem":150,"icon":83},"Identity module","\u002Fmodules\u002Fidentity-management","4.modules\u002F04.identity-management",{"title":152,"path":153,"stem":154,"icon":155},"Cookie sign-in","\u002Fmodules\u002Fcookie-auth","4.modules\u002F05.cookie-auth","i-lucide-cookie",{"title":157,"path":158,"stem":159,"icon":160},"Identity bearer","\u002Fmodules\u002Fbearer-auth","4.modules\u002F06.bearer-auth","i-lucide-key",{"title":162,"path":163,"stem":164,"icon":165},"JWT","\u002Fmodules\u002Fjwt","4.modules\u002F07.jwt","i-lucide-fingerprint",{"title":167,"path":168,"stem":169,"icon":88},"Passkeys","\u002Fmodules\u002Fpasskeys","4.modules\u002F08.passkeys",{"title":171,"path":172,"stem":173,"icon":174},"Step-up ReAuth","\u002Fmodules\u002Freauth","4.modules\u002F09.reauth","i-lucide-shield-alert",{"title":176,"path":177,"stem":178,"icon":58},"External OAuth","\u002Fmodules\u002Fexternal-oauth","4.modules\u002F10.external-oauth",{"title":180,"path":181,"stem":182,"icon":183},"Configuration","\u002Fmodules\u002Fconfiguration","4.modules\u002F11.configuration","i-lucide-settings",{"title":185,"path":186,"stem":187,"icon":98},"CSRF rules","\u002Fmodules\u002Fcsrf","4.modules\u002F12.csrf",{"title":189,"path":190,"stem":191,"icon":192},"Responses","\u002Fmodules\u002Ferrors","4.modules\u002F13.errors","i-lucide-circle-alert",{"title":194,"path":195,"stem":196,"icon":197},"Rate-limit policies","\u002Fmodules\u002Frate-limits","4.modules\u002F14.rate-limits","i-lucide-gauge",{"title":199,"path":200,"stem":201,"icon":73},"Email codes","\u002Fmodules\u002Femail-code","4.modules\u002F15.email-code",{"title":203,"path":204,"stem":205,"icon":78},"OAuth server","\u002Fmodules\u002Fopeniddict","4.modules\u002F16.openiddict",{"title":207,"path":208,"stem":209,"icon":210},"People and agents","\u002Fmodules\u002Fcallers","4.modules\u002F17.callers","i-lucide-user-check",{"title":212,"icon":213,"path":214,"stem":215,"children":216,"page":118},"Concepts","i-lucide-lightbulb","\u002Fconcepts","5.concepts",[217,222,227,232],{"title":218,"path":219,"stem":220,"icon":221},"Comparison","\u002Fconcepts\u002Fcompare","5.concepts\u002F1.compare","i-lucide-git-compare",{"title":223,"path":224,"stem":225,"icon":226},"Security model","\u002Fconcepts\u002Fsecurity-model","5.concepts\u002F2.security-model","i-lucide-shield",{"title":228,"path":229,"stem":230,"icon":231},"Production","\u002Fconcepts\u002Fproduction","5.concepts\u002F3.production","i-lucide-factory",{"title":233,"path":234,"stem":235,"icon":236},"FAQ","\u002Fconcepts\u002Ffaq","5.concepts\u002F4.faq","i-lucide-circle-help",{"id":238,"title":239,"body":240,"description":1783,"extension":1784,"faq":118,"links":1785,"meta":1786,"navigation":1787,"path":116,"seo":1788,"stem":117,"__hash__":1789},"docs\u002F2.guides\u002F15.oauth-grant-context.md","Bind a host context to an OAuth grant",{"type":241,"value":242,"toc":1777},"minimark",[243,252,255,271,279,284,291,936,971,975,1133,1140,1144,1167,1550,1560,1664,1723,1740,1744,1766,1773],[244,245,246,247,251],"p",{},"Many apps have a host context: an organization, workspace, tenant, or region. The person picks one in the UI, and the app keeps it as their current context. When that person connects an OAuth client, such as an AI assistant, the client should work in the context the person chose ",[248,249,250],"strong",{},"at consent",", and stay there.",[244,253,254],{},"Do not read the person's stored current context on calls made with a token. If you do, switching context in the browser silently moves every connected client too. Bind the context to the grant instead:",[256,257,258,262,265,268],"ol",{},[259,260,261],"li",{},"The consent page asks which organization to connect.",[259,263,264],{},"Your approve endpoint checks membership and puts the organization on the token as a claim.",[259,266,267],{},"Your API reads the claim, not the person's current organization.",[259,269,270],{},"A validator checks the membership again at every refresh, and ends the grant when it is gone.",[244,272,273,274,278],{},"It uses the ",[275,276,277],"code",{},"AuthEndpoints.OpenIddict"," package (preview). The examples say \"organization\"; the same steps work for a workspace, a tenant, or a region.",[280,281,283],"h2",{"id":282},"_1-approve-with-the-chosen-organization","1. Approve with the chosen organization",[244,285,286,287,290],{},"Turn off the built-in approve route, or leave it for clients that need no organization, and map your own. The consent page still reads the card from ",[275,288,289],{},"GET \u002Foauth\u002Frequests\u002F{id}",", then posts the person's choice here:",[292,293,298],"pre",{"className":294,"code":295,"language":296,"meta":297,"style":297},"language-csharp shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","public sealed record ApproveForOrganization(string? OrganizationId);\n\napp.MapPost(\"\u002Faccount\u002Foauth\u002Frequests\u002F{id:guid}\u002Fapprove\", async (\n        Guid id, ApproveForOrganization body, HttpContext http, IOAuthConsentService consent, OrganizationMembers members) =>\n    {\n        var userId = http.User.FindFirstValue(ClaimTypes.NameIdentifier)!;\n        if (string.IsNullOrEmpty(body.OrganizationId) || !await members.IsMemberAsync(userId, body.OrganizationId))\n        {\n            return Results.Problem(statusCode: StatusCodes.Status403Forbidden, title: \"Not a member of this organization\");\n        }\n\n        var result = await consent.ApproveAsync(id, userId, context =>\n        {\n            var principal = OAuthPrincipals.ForSubject(context.UserId);\n            principal.SetClaim(OrganizationGrantValidator.OrganizationClaim, body.OrganizationId);\n            foreach (var claim in principal.FindAll(OrganizationGrantValidator.OrganizationClaim))\n            {\n                claim.SetDestinations(OpenIddictConstants.Destinations.AccessToken);\n            }\n\n            return ValueTask.FromResult\u003CClaimsPrincipal?>(principal);\n        });\n\n        return result.Status == OAuthConsentStatus.Approved\n            ? Results.Ok(new { redirectUrl = result.RedirectUrl })\n            : Results.NotFound();\n    })\n    .RequireAuthorization(new AuthorizeAttribute { AuthenticationSchemes = IdentityConstants.ApplicationScheme })\n    .RequireAntiforgery(allowBearer: false);\n","csharp","",[275,299,300,335,342,376,411,417,455,514,520,566,572,577,614,619,650,681,716,722,750,756,761,789,797,802,824,860,878,884,915],{"__ignoreMap":297},[301,302,305,309,312,316,319,323,326,329,332],"span",{"class":303,"line":304},"line",1,[301,306,308],{"class":307},"spNyl","public",[301,310,311],{"class":307}," sealed",[301,313,315],{"class":314},"sBMFI"," record",[301,317,318],{"class":314}," ApproveForOrganization",[301,320,322],{"class":321},"sMK4o","(",[301,324,325],{"class":321},"string",[301,327,328],{"class":321},"?",[301,330,331],{"class":314}," OrganizationId",[301,333,334],{"class":321},");\n",[301,336,338],{"class":303,"line":337},2,[301,339,341],{"emptyLinePlaceholder":340},true,"\n",[301,343,345,349,352,356,358,361,365,367,370,373],{"class":303,"line":344},3,[301,346,348],{"class":347},"sTEyZ","app",[301,350,351],{"class":321},".",[301,353,355],{"class":354},"s2Zo4","MapPost",[301,357,322],{"class":321},[301,359,360],{"class":321},"\"",[301,362,364],{"class":363},"sfazB","\u002Faccount\u002Foauth\u002Frequests\u002F{id:guid}\u002Fapprove",[301,366,360],{"class":321},[301,368,369],{"class":321},",",[301,371,372],{"class":354}," async",[301,374,375],{"class":321}," (\n",[301,377,379,382,384,387,389,392,394,397,399,402,405,408],{"class":303,"line":378},4,[301,380,381],{"class":347},"        Guid id",[301,383,369],{"class":321},[301,385,386],{"class":347}," ApproveForOrganization body",[301,388,369],{"class":321},[301,390,391],{"class":347}," HttpContext http",[301,393,369],{"class":321},[301,395,396],{"class":347}," IOAuthConsentService consent",[301,398,369],{"class":321},[301,400,401],{"class":347}," OrganizationMembers members",[301,403,404],{"class":321},")",[301,406,407],{"class":347}," =",[301,409,410],{"class":321},">\n",[301,412,414],{"class":303,"line":413},5,[301,415,416],{"class":321},"    {\n",[301,418,420,423,426,429,431,434,436,439,441,444,446,449,452],{"class":303,"line":419},6,[301,421,422],{"class":347},"        var userId ",[301,424,425],{"class":321},"=",[301,427,428],{"class":347}," http",[301,430,351],{"class":321},[301,432,433],{"class":347},"User",[301,435,351],{"class":321},[301,437,438],{"class":354},"FindFirstValue",[301,440,322],{"class":321},[301,442,443],{"class":347},"ClaimTypes",[301,445,351],{"class":321},[301,447,448],{"class":347},"NameIdentifier",[301,450,451],{"class":321},")!",[301,453,454],{"class":347},";\n",[301,456,458,461,464,466,468,471,473,476,478,481,483,486,489,492,494,497,499,502,504,507,509,511],{"class":303,"line":457},7,[301,459,460],{"class":354},"        if",[301,462,463],{"class":321}," (",[301,465,325],{"class":321},[301,467,351],{"class":321},[301,469,470],{"class":354},"IsNullOrEmpty",[301,472,322],{"class":321},[301,474,475],{"class":347},"body",[301,477,351],{"class":321},[301,479,480],{"class":347},"OrganizationId",[301,482,404],{"class":321},[301,484,485],{"class":321}," ||",[301,487,488],{"class":321}," !await",[301,490,491],{"class":347}," members",[301,493,351],{"class":321},[301,495,496],{"class":354},"IsMemberAsync",[301,498,322],{"class":321},[301,500,501],{"class":347},"userId",[301,503,369],{"class":321},[301,505,506],{"class":347}," body",[301,508,351],{"class":321},[301,510,480],{"class":347},[301,512,513],{"class":321},"))\n",[301,515,517],{"class":303,"line":516},8,[301,518,519],{"class":321},"        {\n",[301,521,523,526,528,531,533,536,539,542,544,547,549,552,554,557,560,562,564],{"class":303,"line":522},9,[301,524,525],{"class":347},"            return Results",[301,527,351],{"class":321},[301,529,530],{"class":354},"Problem",[301,532,322],{"class":321},[301,534,535],{"class":314},"statusCode",[301,537,538],{"class":321},":",[301,540,541],{"class":347}," StatusCodes",[301,543,351],{"class":321},[301,545,546],{"class":347},"Status403Forbidden",[301,548,369],{"class":321},[301,550,551],{"class":314}," title",[301,553,538],{"class":321},[301,555,556],{"class":321}," \"",[301,558,559],{"class":363},"Not a member of this organization",[301,561,360],{"class":321},[301,563,404],{"class":321},[301,565,454],{"class":347},[301,567,569],{"class":303,"line":568},10,[301,570,571],{"class":321},"        }\n",[301,573,575],{"class":303,"line":574},11,[301,576,341],{"emptyLinePlaceholder":340},[301,578,580,583,585,588,591,593,596,598,601,603,606,608,611],{"class":303,"line":579},12,[301,581,582],{"class":347},"        var result ",[301,584,425],{"class":321},[301,586,587],{"class":321}," await",[301,589,590],{"class":347}," consent",[301,592,351],{"class":321},[301,594,595],{"class":354},"ApproveAsync",[301,597,322],{"class":321},[301,599,600],{"class":347},"id",[301,602,369],{"class":321},[301,604,605],{"class":347}," userId",[301,607,369],{"class":321},[301,609,610],{"class":314}," context",[301,612,613],{"class":321}," =>\n",[301,615,617],{"class":303,"line":616},13,[301,618,519],{"class":321},[301,620,622,625,628,630,633,635,638,640,643,645,648],{"class":303,"line":621},14,[301,623,624],{"class":314},"            var",[301,626,627],{"class":314}," principal",[301,629,407],{"class":321},[301,631,632],{"class":347}," OAuthPrincipals",[301,634,351],{"class":321},[301,636,637],{"class":354},"ForSubject",[301,639,322],{"class":321},[301,641,642],{"class":347},"context",[301,644,351],{"class":321},[301,646,647],{"class":347},"UserId",[301,649,334],{"class":321},[301,651,653,656,658,661,663,666,668,671,673,675,677,679],{"class":303,"line":652},15,[301,654,655],{"class":347},"            principal",[301,657,351],{"class":321},[301,659,660],{"class":354},"SetClaim",[301,662,322],{"class":321},[301,664,665],{"class":347},"OrganizationGrantValidator",[301,667,351],{"class":321},[301,669,670],{"class":347},"OrganizationClaim",[301,672,369],{"class":321},[301,674,506],{"class":347},[301,676,351],{"class":321},[301,678,480],{"class":347},[301,680,334],{"class":321},[301,682,684,688,690,693,696,699,701,703,706,708,710,712,714],{"class":303,"line":683},16,[301,685,687],{"class":686},"s7zQu","            foreach",[301,689,463],{"class":321},[301,691,692],{"class":314},"var",[301,694,695],{"class":314}," claim",[301,697,698],{"class":686}," in",[301,700,627],{"class":347},[301,702,351],{"class":321},[301,704,705],{"class":354},"FindAll",[301,707,322],{"class":321},[301,709,665],{"class":347},[301,711,351],{"class":321},[301,713,670],{"class":347},[301,715,513],{"class":321},[301,717,719],{"class":303,"line":718},17,[301,720,721],{"class":321},"            {\n",[301,723,725,728,730,733,735,738,740,743,745,748],{"class":303,"line":724},18,[301,726,727],{"class":347},"                claim",[301,729,351],{"class":321},[301,731,732],{"class":354},"SetDestinations",[301,734,322],{"class":321},[301,736,737],{"class":347},"OpenIddictConstants",[301,739,351],{"class":321},[301,741,742],{"class":347},"Destinations",[301,744,351],{"class":321},[301,746,747],{"class":347},"AccessToken",[301,749,334],{"class":321},[301,751,753],{"class":303,"line":752},19,[301,754,755],{"class":321},"            }\n",[301,757,759],{"class":303,"line":758},20,[301,760,341],{"emptyLinePlaceholder":340},[301,762,764,767,770,772,775,778,781,784,787],{"class":303,"line":763},21,[301,765,766],{"class":686},"            return",[301,768,769],{"class":347}," ValueTask",[301,771,351],{"class":321},[301,773,774],{"class":354},"FromResult",[301,776,777],{"class":321},"\u003C",[301,779,780],{"class":314},"ClaimsPrincipal",[301,782,783],{"class":321},"?>(",[301,785,786],{"class":347},"principal",[301,788,334],{"class":321},[301,790,792,795],{"class":303,"line":791},22,[301,793,794],{"class":321},"        })",[301,796,454],{"class":347},[301,798,800],{"class":303,"line":799},23,[301,801,341],{"emptyLinePlaceholder":340},[301,803,805,808,810,813,816,819,821],{"class":303,"line":804},24,[301,806,807],{"class":347},"        return result",[301,809,351],{"class":321},[301,811,812],{"class":347},"Status ",[301,814,815],{"class":321},"==",[301,817,818],{"class":347}," OAuthConsentStatus",[301,820,351],{"class":321},[301,822,823],{"class":347},"Approved\n",[301,825,827,830,833,835,838,841,844,847,849,852,854,857],{"class":303,"line":826},25,[301,828,829],{"class":321},"            ?",[301,831,832],{"class":347}," Results",[301,834,351],{"class":321},[301,836,837],{"class":354},"Ok",[301,839,840],{"class":321},"(new",[301,842,843],{"class":321}," {",[301,845,846],{"class":347}," redirectUrl ",[301,848,425],{"class":321},[301,850,851],{"class":347}," result",[301,853,351],{"class":321},[301,855,856],{"class":347},"RedirectUrl ",[301,858,859],{"class":321},"})\n",[301,861,863,866,868,870,873,876],{"class":303,"line":862},26,[301,864,865],{"class":321},"            :",[301,867,832],{"class":347},[301,869,351],{"class":321},[301,871,872],{"class":354},"NotFound",[301,874,875],{"class":321},"()",[301,877,454],{"class":347},[301,879,881],{"class":303,"line":880},27,[301,882,883],{"class":321},"    })\n",[301,885,887,890,893,895,898,900,903,905,908,910,913],{"class":303,"line":886},28,[301,888,889],{"class":321},"    .",[301,891,892],{"class":354},"RequireAuthorization",[301,894,840],{"class":321},[301,896,897],{"class":314}," AuthorizeAttribute",[301,899,843],{"class":321},[301,901,902],{"class":347}," AuthenticationSchemes ",[301,904,425],{"class":321},[301,906,907],{"class":347}," IdentityConstants",[301,909,351],{"class":321},[301,911,912],{"class":347},"ApplicationScheme ",[301,914,859],{"class":321},[301,916,918,920,923,925,928,930,934],{"class":303,"line":917},29,[301,919,889],{"class":321},[301,921,922],{"class":354},"RequireAntiforgery",[301,924,322],{"class":321},[301,926,927],{"class":314},"allowBearer",[301,929,538],{"class":321},[301,931,933],{"class":932},"sfNiH"," false",[301,935,334],{"class":321},[937,938,939,942,956,963],"ul",{},[259,940,941],{},"The membership check runs before anything is consumed. A refused request stays open, so the person can pick another organization.",[259,943,944,947,948,951,952,955],{},[275,945,946],{},"sub"," stays the person's user id, so ",[275,949,950],{},"AccessTokenClaims.Roles"," and ",[275,953,954],{},"AccessTokenClaims.UserId"," still work.",[259,957,958,959,962],{},"The ",[275,960,961],{},"org_id"," claim is stored in the code and the refresh token. Every access token issued from this grant carries the same value. Nothing is written to the person's record.",[259,964,965,966,351],{},"If the organization decides who the token acts as (a service account per organization), return that subject from the callback instead. See ",[967,968,970],"a",{"href":969},"https:\u002F\u002Fgithub.com\u002Fmadeyoga\u002FAuthEndpoints\u002Ftree\u002Fmain\u002Fsrc\u002FAuthEndpoints.OpenIddict#who-is-the-token-subject","Who is the token subject",[280,972,974],{"id":973},"_2-read-it-in-the-api","2. Read it in the API",[292,976,978],{"className":294,"code":977,"language":296,"meta":297,"style":297},"app.MapGet(\"\u002Fapi\u002Freports\", (ClaimsPrincipal user, ReportStore reports) =>\n{\n    var organization = user.FindFirst(\"org_id\")?.Value; \u002F\u002F from the token, never from the user's current organization\n    return organization is null ? Results.Forbid() : Results.Ok(reports.For(organization));\n}).RequireAuthorization(\"api\");\n",[275,979,980,1019,1024,1062,1115],{"__ignoreMap":297},[301,981,982,984,986,989,991,993,996,998,1000,1002,1004,1007,1009,1012,1015,1017],{"class":303,"line":304},[301,983,348],{"class":347},[301,985,351],{"class":321},[301,987,988],{"class":354},"MapGet",[301,990,322],{"class":321},[301,992,360],{"class":321},[301,994,995],{"class":363},"\u002Fapi\u002Freports",[301,997,360],{"class":321},[301,999,369],{"class":321},[301,1001,463],{"class":321},[301,1003,780],{"class":314},[301,1005,1006],{"class":314}," user",[301,1008,369],{"class":321},[301,1010,1011],{"class":314}," ReportStore",[301,1013,1014],{"class":314}," reports",[301,1016,404],{"class":321},[301,1018,613],{"class":321},[301,1020,1021],{"class":303,"line":337},[301,1022,1023],{"class":321},"{\n",[301,1025,1026,1029,1032,1034,1036,1038,1041,1043,1045,1047,1049,1052,1055,1058],{"class":303,"line":344},[301,1027,1028],{"class":314},"    var",[301,1030,1031],{"class":314}," organization",[301,1033,407],{"class":321},[301,1035,1006],{"class":347},[301,1037,351],{"class":321},[301,1039,1040],{"class":354},"FindFirst",[301,1042,322],{"class":321},[301,1044,360],{"class":321},[301,1046,961],{"class":363},[301,1048,360],{"class":321},[301,1050,1051],{"class":321},")?.",[301,1053,1054],{"class":347},"Value",[301,1056,1057],{"class":321},";",[301,1059,1061],{"class":1060},"sHwdD"," \u002F\u002F from the token, never from the user's current organization\n",[301,1063,1064,1067,1070,1073,1076,1079,1081,1083,1086,1088,1091,1093,1095,1097,1099,1102,1104,1107,1109,1112],{"class":303,"line":378},[301,1065,1066],{"class":686},"    return",[301,1068,1069],{"class":347}," organization ",[301,1071,1072],{"class":321},"is",[301,1074,1075],{"class":321}," null",[301,1077,1078],{"class":321}," ?",[301,1080,832],{"class":347},[301,1082,351],{"class":321},[301,1084,1085],{"class":354},"Forbid",[301,1087,875],{"class":321},[301,1089,1090],{"class":321}," :",[301,1092,832],{"class":347},[301,1094,351],{"class":321},[301,1096,837],{"class":354},[301,1098,322],{"class":321},[301,1100,1101],{"class":347},"reports",[301,1103,351],{"class":321},[301,1105,1106],{"class":354},"For",[301,1108,322],{"class":321},[301,1110,1111],{"class":347},"organization",[301,1113,1114],{"class":321},"));\n",[301,1116,1117,1120,1122,1124,1126,1129,1131],{"class":303,"line":413},[301,1118,1119],{"class":321},"}).",[301,1121,892],{"class":354},[301,1123,322],{"class":321},[301,1125,360],{"class":321},[301,1127,1128],{"class":363},"api",[301,1130,360],{"class":321},[301,1132,334],{"class":321},[244,1134,1135,1136,1139],{},"On routes that cookie users share, use the claim when ",[275,1137,1138],{},"User.IsOAuthDelegated()"," is true, and the person's current organization otherwise.",[280,1141,1143],{"id":1142},"_3-check-it-again-at-every-refresh","3. Check it again at every refresh",[244,1145,1146,1147,1150,1151,1154,1155,1158,1159,1162,1163,1166],{},"The server already checks the person at every code exchange and refresh (",[275,1148,1149],{},"RevalidateUser",", on by default) through ",[275,1152,1153],{},"IOAuthUserValidator",". Its ",[275,1156,1157],{},"ValidateAsync"," method gets an ",[275,1160,1161],{},"OAuthUserValidationContext"," with the grant's own claims in ",[275,1164,1165],{},"Grant",", so it can read the organization the approve endpoint bound. Wrap the default validator and check membership too:",[292,1168,1170],{"className":294,"code":1169,"language":296,"meta":297,"style":297},"public sealed class OrganizationGrantValidator(\n    IdentityOAuthUserValidator\u003CAppUser> identity,\n    OrganizationMembers members) : IOAuthUserValidator\n{\n    public const string OrganizationClaim = \"org_id\";\n\n    public ValueTask\u003Cstring?> GetStampAsync(string userId, CancellationToken cancellationToken)\n        => identity.GetStampAsync(userId, cancellationToken);\n\n    public ValueTask\u003Cbool> IsValidAsync(string userId, string? stamp, CancellationToken cancellationToken)\n        => identity.IsValidAsync(userId, stamp, cancellationToken);\n\n    \u002F\u002F Runs at every code exchange and refresh.\n    public async ValueTask\u003Cbool> ValidateAsync(OAuthUserValidationContext context, CancellationToken cancellationToken)\n    {\n        if (!await identity.IsValidAsync(context.UserId, context.SecurityStamp, cancellationToken))\n        {\n            return false;\n        }\n\n        \u002F\u002F Grants approved without an organization (the built-in consent API) have no claim to check.\n        return context.Grant.FindFirst(OrganizationClaim)?.Value is not { } organization\n            || await members.IsMemberAsync(context.UserId, organization, cancellationToken);\n    }\n}\n",[275,1171,1172,1187,1206,1220,1224,1248,1252,1285,1307,1311,1346,1371,1375,1380,1407,1411,1447,1451,1459,1463,1467,1472,1509,1540,1545],{"__ignoreMap":297},[301,1173,1174,1176,1178,1181,1184],{"class":303,"line":304},[301,1175,308],{"class":307},[301,1177,311],{"class":307},[301,1179,1180],{"class":314}," class",[301,1182,1183],{"class":314}," OrganizationGrantValidator",[301,1185,1186],{"class":321},"(\n",[301,1188,1189,1192,1194,1197,1200,1203],{"class":303,"line":337},[301,1190,1191],{"class":314},"    IdentityOAuthUserValidator",[301,1193,777],{"class":321},[301,1195,1196],{"class":314},"AppUser",[301,1198,1199],{"class":321},">",[301,1201,1202],{"class":314}," identity",[301,1204,1205],{"class":321},",\n",[301,1207,1208,1211,1213,1215,1217],{"class":303,"line":344},[301,1209,1210],{"class":314},"    OrganizationMembers",[301,1212,491],{"class":314},[301,1214,404],{"class":321},[301,1216,1090],{"class":321},[301,1218,1219],{"class":314}," IOAuthUserValidator\n",[301,1221,1222],{"class":303,"line":378},[301,1223,1023],{"class":321},[301,1225,1226,1229,1232,1235,1238,1240,1242,1244,1246],{"class":303,"line":413},[301,1227,1228],{"class":307},"    public",[301,1230,1231],{"class":307}," const",[301,1233,1234],{"class":321}," string",[301,1236,1237],{"class":314}," OrganizationClaim",[301,1239,407],{"class":321},[301,1241,556],{"class":321},[301,1243,961],{"class":363},[301,1245,360],{"class":321},[301,1247,454],{"class":321},[301,1249,1250],{"class":303,"line":419},[301,1251,341],{"emptyLinePlaceholder":340},[301,1253,1254,1256,1258,1260,1262,1265,1268,1270,1272,1274,1276,1279,1282],{"class":303,"line":457},[301,1255,1228],{"class":307},[301,1257,769],{"class":314},[301,1259,777],{"class":321},[301,1261,325],{"class":321},[301,1263,1264],{"class":321},"?>",[301,1266,1267],{"class":354}," GetStampAsync",[301,1269,322],{"class":321},[301,1271,325],{"class":321},[301,1273,605],{"class":314},[301,1275,369],{"class":321},[301,1277,1278],{"class":314}," CancellationToken",[301,1280,1281],{"class":314}," cancellationToken",[301,1283,1284],{"class":321},")\n",[301,1286,1287,1290,1292,1294,1297,1299,1301,1303,1305],{"class":303,"line":516},[301,1288,1289],{"class":321},"        =>",[301,1291,1202],{"class":347},[301,1293,351],{"class":321},[301,1295,1296],{"class":354},"GetStampAsync",[301,1298,322],{"class":321},[301,1300,501],{"class":347},[301,1302,369],{"class":321},[301,1304,1281],{"class":347},[301,1306,334],{"class":321},[301,1308,1309],{"class":303,"line":522},[301,1310,341],{"emptyLinePlaceholder":340},[301,1312,1313,1315,1317,1320,1323,1325,1327,1329,1331,1333,1335,1338,1340,1342,1344],{"class":303,"line":568},[301,1314,1228],{"class":307},[301,1316,769],{"class":314},[301,1318,1319],{"class":321},"\u003Cbool>",[301,1321,1322],{"class":354}," IsValidAsync",[301,1324,322],{"class":321},[301,1326,325],{"class":321},[301,1328,605],{"class":314},[301,1330,369],{"class":321},[301,1332,1234],{"class":321},[301,1334,328],{"class":321},[301,1336,1337],{"class":314}," stamp",[301,1339,369],{"class":321},[301,1341,1278],{"class":314},[301,1343,1281],{"class":314},[301,1345,1284],{"class":321},[301,1347,1348,1350,1352,1354,1357,1359,1361,1363,1365,1367,1369],{"class":303,"line":574},[301,1349,1289],{"class":321},[301,1351,1202],{"class":347},[301,1353,351],{"class":321},[301,1355,1356],{"class":354},"IsValidAsync",[301,1358,322],{"class":321},[301,1360,501],{"class":347},[301,1362,369],{"class":321},[301,1364,1337],{"class":347},[301,1366,369],{"class":321},[301,1368,1281],{"class":347},[301,1370,334],{"class":321},[301,1372,1373],{"class":303,"line":579},[301,1374,341],{"emptyLinePlaceholder":340},[301,1376,1377],{"class":303,"line":616},[301,1378,1379],{"class":1060},"    \u002F\u002F Runs at every code exchange and refresh.\n",[301,1381,1382,1384,1386,1388,1390,1393,1395,1397,1399,1401,1403,1405],{"class":303,"line":621},[301,1383,1228],{"class":307},[301,1385,372],{"class":307},[301,1387,769],{"class":314},[301,1389,1319],{"class":321},[301,1391,1392],{"class":354}," ValidateAsync",[301,1394,322],{"class":321},[301,1396,1161],{"class":314},[301,1398,610],{"class":314},[301,1400,369],{"class":321},[301,1402,1278],{"class":314},[301,1404,1281],{"class":314},[301,1406,1284],{"class":321},[301,1408,1409],{"class":303,"line":652},[301,1410,416],{"class":321},[301,1412,1413,1415,1418,1420,1422,1424,1426,1428,1430,1432,1434,1436,1438,1441,1443,1445],{"class":303,"line":683},[301,1414,460],{"class":686},[301,1416,1417],{"class":321}," (!await",[301,1419,1202],{"class":347},[301,1421,351],{"class":321},[301,1423,1356],{"class":354},[301,1425,322],{"class":321},[301,1427,642],{"class":347},[301,1429,351],{"class":321},[301,1431,647],{"class":347},[301,1433,369],{"class":321},[301,1435,610],{"class":347},[301,1437,351],{"class":321},[301,1439,1440],{"class":347},"SecurityStamp",[301,1442,369],{"class":321},[301,1444,1281],{"class":347},[301,1446,513],{"class":321},[301,1448,1449],{"class":303,"line":718},[301,1450,519],{"class":321},[301,1452,1453,1455,1457],{"class":303,"line":724},[301,1454,766],{"class":686},[301,1456,933],{"class":932},[301,1458,454],{"class":321},[301,1460,1461],{"class":303,"line":752},[301,1462,571],{"class":321},[301,1464,1465],{"class":303,"line":758},[301,1466,341],{"emptyLinePlaceholder":340},[301,1468,1469],{"class":303,"line":763},[301,1470,1471],{"class":1060},"        \u002F\u002F Grants approved without an organization (the built-in consent API) have no claim to check.\n",[301,1473,1474,1477,1479,1481,1483,1485,1487,1489,1491,1493,1496,1498,1501,1503,1506],{"class":303,"line":791},[301,1475,1476],{"class":686},"        return",[301,1478,610],{"class":347},[301,1480,351],{"class":321},[301,1482,1165],{"class":347},[301,1484,351],{"class":321},[301,1486,1040],{"class":354},[301,1488,322],{"class":321},[301,1490,670],{"class":347},[301,1492,1051],{"class":321},[301,1494,1495],{"class":347},"Value ",[301,1497,1072],{"class":321},[301,1499,1500],{"class":321}," not",[301,1502,843],{"class":321},[301,1504,1505],{"class":321}," }",[301,1507,1508],{"class":314}," organization\n",[301,1510,1511,1514,1516,1518,1520,1522,1524,1526,1528,1530,1532,1534,1536,1538],{"class":303,"line":799},[301,1512,1513],{"class":321},"            ||",[301,1515,587],{"class":321},[301,1517,491],{"class":347},[301,1519,351],{"class":321},[301,1521,496],{"class":354},[301,1523,322],{"class":321},[301,1525,642],{"class":347},[301,1527,351],{"class":321},[301,1529,647],{"class":347},[301,1531,369],{"class":321},[301,1533,1031],{"class":347},[301,1535,369],{"class":321},[301,1537,1281],{"class":347},[301,1539,334],{"class":321},[301,1541,1542],{"class":303,"line":804},[301,1543,1544],{"class":321},"    }\n",[301,1546,1547],{"class":303,"line":826},[301,1548,1549],{"class":321},"}\n",[244,1551,1552,1553,1556,1557,538],{},"Register it after ",[275,1554,1555],{},"AddOAuthServer",", which registers the default with ",[275,1558,1559],{},"TryAdd",[292,1561,1563],{"className":294,"code":1562,"language":296,"meta":297,"style":297},"builder.Services.AddOAuthServer\u003CAppUser, AppDbContext>(options => { \u002F* … *\u002F });\nbuilder.Services.AddScoped\u003CIdentityOAuthUserValidator\u003CAppUser>>();\nbuilder.Services.Replace(ServiceDescriptor.Scoped\u003CIOAuthUserValidator, OrganizationGrantValidator>());\n",[275,1564,1565,1605,1630],{"__ignoreMap":297},[301,1566,1567,1570,1572,1575,1577,1579,1581,1583,1585,1588,1591,1594,1597,1599,1602],{"class":303,"line":304},[301,1568,1569],{"class":347},"builder",[301,1571,351],{"class":321},[301,1573,1574],{"class":347},"Services",[301,1576,351],{"class":321},[301,1578,1555],{"class":354},[301,1580,777],{"class":321},[301,1582,1196],{"class":314},[301,1584,369],{"class":321},[301,1586,1587],{"class":314}," AppDbContext",[301,1589,1590],{"class":321},">(",[301,1592,1593],{"class":314},"options",[301,1595,1596],{"class":321}," =>",[301,1598,843],{"class":321},[301,1600,1601],{"class":1060}," \u002F* … *\u002F",[301,1603,1604],{"class":321}," });\n",[301,1606,1607,1609,1611,1613,1615,1618,1620,1623,1625,1627],{"class":303,"line":337},[301,1608,1569],{"class":347},[301,1610,351],{"class":321},[301,1612,1574],{"class":347},[301,1614,351],{"class":321},[301,1616,1617],{"class":354},"AddScoped",[301,1619,777],{"class":321},[301,1621,1622],{"class":314},"IdentityOAuthUserValidator",[301,1624,777],{"class":321},[301,1626,1196],{"class":314},[301,1628,1629],{"class":321},">>();\n",[301,1631,1632,1634,1636,1638,1640,1643,1645,1648,1650,1653,1655,1657,1659,1661],{"class":303,"line":344},[301,1633,1569],{"class":347},[301,1635,351],{"class":321},[301,1637,1574],{"class":347},[301,1639,351],{"class":321},[301,1641,1642],{"class":354},"Replace",[301,1644,322],{"class":321},[301,1646,1647],{"class":347},"ServiceDescriptor",[301,1649,351],{"class":321},[301,1651,1652],{"class":354},"Scoped",[301,1654,777],{"class":321},[301,1656,1153],{"class":314},[301,1658,369],{"class":321},[301,1660,1183],{"class":314},[301,1662,1663],{"class":321},">());\n",[937,1665,1666,1669,1683,1714],{},[259,1667,1668],{},"The Identity checks still apply: a changed password or security stamp, a lockout, or a deleted account ends the grant.",[259,1670,1671,1672,1675,1676,1679,1680,351],{},"When the person leaves the organization, the next refresh gets ",[275,1673,1674],{},"invalid_grant"," and the grant and its tokens are revoked. An access token that was already issued works until it expires (",[275,1677,1678],{},"AccessTokenLifetime",", 15 minutes by default). To cut it off at once, revoke the grant when you remove the membership, with ",[275,1681,1682],{},"IOAuthConsentService.RevokeAuthorizationAsync",[259,1684,1685,1688,1689,1691,1692,1695,1696,1699,1700,1699,1703,1699,1706,1709,1710,1713],{},[275,1686,1687],{},"context.Grant"," holds the claims of the code or refresh token: ",[275,1690,946],{}," and what your callback added. The package's internal claims (the approving user id and stamp) and OpenIddict's ",[275,1693,1694],{},"oi_*"," claims are removed. Use ",[275,1697,1698],{},"context.UserId",", ",[275,1701,1702],{},"context.SecurityStamp",[275,1704,1705],{},"context.Scopes",[275,1707,1708],{},"context.ClientId",", and ",[275,1711,1712],{},"context.AuthorizationId"," for those.",[259,1715,1716,1718,1719,1722],{},[275,1717,1157],{}," has a default that calls ",[275,1720,1721],{},"IsValidAsync(userId, stamp)",", so validators written before it existed keep working unchanged.",[244,1724,1725,1726,1728,1729,1732,1733,1736,1737,1739],{},"Earlier versions of this guide carried the organization inside the stored stamp (",[275,1727,1296],{}," returned ",[275,1730,1731],{},"organization|stamp",", read from ",[275,1734,1735],{},"HttpContext.Items","), because the validator could not see the grant. That still works, but read ",[275,1738,1687],{}," instead: it keeps app data out of a security value.",[280,1741,1743],{"id":1742},"checklist","Checklist",[937,1745,1746,1749,1755,1758],{},[259,1747,1748],{},"The consent page asks for the organization and posts it to your approve endpoint.",[259,1750,1751,1752,1754],{},"The approve endpoint checks membership before ",[275,1753,595],{},", and puts the organization on the token.",[259,1756,1757],{},"APIs called with tokens read the claim, not the person's current organization.",[259,1759,1760,1762,1763,1765],{},[275,1761,665],{}," replaces ",[275,1764,1153],{},", so removing a membership ends the grant at its next refresh.",[244,1767,1768,1769,1772],{},"The package's tests run this guide's code: ",[275,1770,1771],{},"OAuthGrantContextRecipeTests"," in the repository.",[1774,1775,1776],"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 .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}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);}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}",{"title":297,"searchDepth":304,"depth":337,"links":1778},[1779,1780,1781,1782],{"id":282,"depth":337,"text":283},{"id":973,"depth":337,"text":974},{"id":1142,"depth":337,"text":1143},{"id":1742,"depth":337,"text":1743},"Keep an OAuth client in the organization, workspace, or region the person chose at consent, and check it again at every refresh.","md",null,{},{"title":115,"icon":103},{"title":239,"description":1783},"nnChwZaRDembo4wljtLCYWfTCyflHFjU7v6B5tbctwc",[1791,1793],{"title":110,"path":111,"stem":112,"description":1792,"icon":113,"children":-1},"Let AI assistants and other MCP clients connect to your app as the signed-in person, with that person's roles and only the scopes they approved.",{"title":125,"path":121,"stem":122,"description":1794,"icon":126,"children":-1},"Compose Add and Map pairs on your prefixes. A custom host follows the rules and can copy a host for email-code, external, passkey, or JWT sign-in.",1795238828359]