[{"data":1,"prerenderedAt":4230},["Reactive",2],{"navigation":3,"/posts/delegating-handler":204,"/posts/delegating-handler-surround":4201},[4,192,200],{"title":5,"_path":6,"children":7,"icon":191},"Blog","/posts",[8,11,14,17,20,23,26,29,32,35,38,41,44,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,92,95,98,101,104,107,110,113,116,119,122,125,128,131,134,137,140,143,146,149,152,155,158,161,164,167,170,173,176,179,182,185,188],{"title":9,"_path":10},"Testing your API with REST Client","/posts/testing-your-api-with-rest-client",{"title":12,"_path":13},"HTML templating in Xamarin","/posts/html-templating-in-xamarin",{"title":15,"_path":16},"Goodbye Azure Portal, Welcome Azure CLI","/posts/welcome-azure-cli",{"title":18,"_path":19},"Coming across Gitpod","/posts/gitpod",{"title":21,"_path":22},"Handle token retrieval while querying an API","/posts/delegating-handler",{"title":24,"_path":25},"Clean up your local git branches.","/posts/cleaning-git-branches",{"title":27,"_path":28},"Automate configuration of Teams Tab SSO with PowerShell.","/posts/teams-sso-powershell",{"title":30,"_path":31},"How to do a technology watch? - Part 1","/posts/technology-watch-part1",{"title":33,"_path":34},"How to do a technology watch? - Part 2","/posts/technology-watch-part2",{"title":36,"_path":37},"You almost no longer need Key Vault references for Azure Functions.","/posts/azure-functions-custom-configuration",{"title":39,"_path":40},"How to do a technology watch? - Part 3","/posts/technology-watch-part3",{"title":42,"_path":43},"Forget DevOps, the future is already here!","/posts/devops-future",{"title":45,"_path":46},"Week 9, 2021 - Tips I learned this week","/posts/w09-2021-tips-learned-this-week",{"title":48,"_path":49},"Week 12, 2021 - Tips I learned this week","/posts/w12-2021-tips-learned-this-week",{"title":51,"_path":52},"Week 14, 2021 - Tips I learned this week","/posts/w14-2021-tips-learned-this-week",{"title":54,"_path":55},"Once upon a time in .NET","/posts/once-upon-a-time-in-dotnet",{"title":57,"_path":58},"Install your applications with winget","/posts/winget-import",{"title":60,"_path":61},"Customize your applications when installing them with winget","/posts/winget-override",{"title":63,"_path":64},"Week 22, 2021 - Tips I learned this week","/posts/w22-2021-tips-learned-this-week",{"title":66,"_path":67},"How to connect to an Azure SQL Database from C# using Azure AD","/posts/sqlclient-active-directory-authent",{"title":69,"_path":70},"Producing packages for Windows Package Manager","/posts/wingetcreate",{"title":72,"_path":73},"4 tips about GitHub Actions environment variables and contexts","/posts/github-actions-var-and-context",{"title":75,"_path":76},"AzureWebJobsStorage, the secret you don't need in your Function App.","/posts/azure-functions-without-azurewebjobsstorage",{"title":78,"_path":79},"ASP.NET Core - Lost in configuration","/posts/lost-in-configuration",{"title":81,"_path":82},"Week 39, 2021 - Tips I learned this week","/posts/w39-2021-tips-learned-this-week",{"title":84,"_path":85},"Week 41, 2021 - Tips I learned this week","/posts/w41-2021-tips-learned-this-week",{"title":87,"_path":88},"Migrating and open-sourcing my blog","/posts/migrating-blog",{"title":90,"_path":91},"Week 45, 2021 - Tips I learned this week","/posts/w45-2021-tips-learned-this-week",{"title":93,"_path":94},"Organize your GitHub stars with Astral","/posts/astral",{"title":96,"_path":97},"Pulumi with an Azure Blob Storage backend","/posts/pulumi-azure-backend",{"title":99,"_path":100},"IaC Hot Reload with Pulumi Watch","/posts/pulumi-watch",{"title":102,"_path":103},"Week 2, 2022 - Tips I learned this week","/posts/w02-2022-tips-learned-this-week",{"title":105,"_path":106},"Week 3, 2022 - Tips I learned this week","/posts/w03-2022-tips-learned-this-week",{"title":108,"_path":109},"Week 5, 2022 - Tips I learned this week","/posts/w05-2022-tips-learned-this-week",{"title":111,"_path":112},"How to provision an Azure SQL Database with Active Directory authentication","/posts/sqldatabase-active-directory-authent",{"title":114,"_path":115},"Why will I choose Pulumi over Terraform for my next project?","/posts/pulumi-vs-terraform",{"title":117,"_path":118},"Week 19, 2022 - Tips I learned this week","/posts/w19-2022-tips-learned-this-week",{"title":120,"_path":121},"Week 20, 2022 - Tips I learned this week","/posts/w20-2022-tips-learned-this-week",{"title":123,"_path":124},"Keeping secrets secure when using API Clients","/posts/http-clients-secrets",{"title":126,"_path":127},"What made me want to be a developer?","/posts/be-a-developer",{"title":129,"_path":130},"What can we do when stuck with a programming problem?","/posts/get-unstuck",{"title":132,"_path":133},"How did I automate the setup of my developer Windows laptop?","/posts/automate-developer-machine",{"title":135,"_path":136},"Discussion about API clients","/posts/http-clients",{"title":138,"_path":139},"Week 46, 2022 - Tips I learned this week","/posts/w46-2022-tips-learned-this-week",{"title":141,"_path":142},"When Pulumi met Nuke: a .NET love story","/posts/when-pulumi-met-nuke",{"title":144,"_path":145},"A year of learning and sharing - Dev Retro 2022","/posts/2022-retro",{"title":147,"_path":148},"Perform Dynamic Execution of an npm Package","/posts/pnpm-dlx",{"title":150,"_path":151},"Manage multiple Node.js versions","/posts/pnpm-env",{"title":153,"_path":154},"Introducing the Vue.js CI/CD series","/posts/vuecicd-introduction",{"title":156,"_path":157},"Execute commands using your project dependencies","/posts/pnpm-exec",{"title":159,"_path":160},"Vue.js CI/CD: Continuous Integration","/posts/vuecicd-ci",{"title":162,"_path":163},"Who is using pnpm?","/posts/pnpm-who-is-using",{"title":165,"_path":166},"Create an Azure-Ready GitHub Repository using Pulumi","/posts/azure-ready-github-repository",{"title":168,"_path":169},"Deploying to Azure from Azure DevOps without secrets","/posts/ado-workload-identity-federation",{"title":171,"_path":172},"Effortlessly Configure GitHub Repositories for Azure Deployment via OIDC","/posts/scripting-azure-ready-github-repository",{"title":174,"_path":175},"Playing with the .NET 8 Web API template","/posts/playing-with-dotnet8",{"title":177,"_path":178},"Another year of sharing and learning - Dev Retro 2023","/posts/2023-retro",{"title":180,"_path":181},"Week 4, 2024 - Tips I learned this week","/posts/w04-2024-tips-learned-this-week",{"title":183,"_path":184},"Using dependency injection with Azure .NET SDK","/posts/azure-sdk-di",{"title":186,"_path":187},"Having Fun With IT Event Calendars","/posts/it-event-calendars",{"title":189,"_path":190},"Call your Azure AD B2C protected API with authenticated HTTP requests from your JetBrains IDE","/posts/http-clients-oauth2","i-heroicons-newspaper",{"title":193,"_path":194,"children":195,"icon":199},"Goodies","/goodies",[196],{"title":197,"_path":198},"My Git Cheat Sheet","/goodies/gitcheatsheet","i-heroicons-gift-solid",{"title":201,"_path":202,"icon":203},"About","/about","i-heroicons-user-circle-solid",{"_path":22,"_dir":205,"_draft":206,"_partial":206,"_locale":207,"title":21,"description":208,"lead":209,"date":210,"image":211,"badge":213,"tags":215,"body":220,"_type":4196,"_id":4197,"_source":4198,"_file":4199,"_extension":4200},"posts",false,"","In our daily job, we often have to query secure REST APIs that require our HTTP requests to have a valid access token in their Authorization header.\nOf course, many APIs come with an SDK that makes the job easier for us as it directly takes care of retrieving a token and sending the authenticated HTTP requests.\nHowever, it is not always the case and knowing how to implement that using HttpClient, IMemoryCache, and DelegatingHandler can become pretty useful.","Using a DelegatingHandler","2020-01-29T00:00:00.000Z",{"src":212},"/images/keyboard_1.jpg",{"label":214},"Development",[216,217,218,219],"HTTP","rest","ASP.NET Core",".NET",{"type":221,"children":222,"toc":4189},"root",[223,230,237,242,254,292,297,337,465,477,482,727,745,870,883,889,915,2075,2080,2115,2121,2162,2818,2841,2847,2886,2921,2933,3304,3309,3837,3850,4172,4178,4183],{"type":224,"tag":225,"props":226,"children":227},"element","p",{},[228],{"type":229,"value":208},"text",{"type":224,"tag":231,"props":232,"children":234},"h2",{"id":233},"context",[235],{"type":229,"value":236},"Context",{"type":224,"tag":225,"props":238,"children":239},{},[240],{"type":229,"value":241},"Let's imagine we have a very simple API that contains the following routes :",{"type":224,"tag":225,"props":243,"children":244},{},[245],{"type":224,"tag":246,"props":247,"children":253},"img",{"alt":248,"className":249,"src":252},"Open API specifications of the Users API",[250,251],"rounded-lg","mx-auto","/posts/images/delegatinghandler_api_1.png",[],{"type":224,"tag":225,"props":255,"children":256},{},[257,259,266,268,274,276,282,284,290],{"type":229,"value":258},"The ",{"type":224,"tag":260,"props":261,"children":263},"code",{"className":262},[],[264],{"type":229,"value":265},"POST /login",{"type":229,"value":267}," route returns an ",{"type":224,"tag":260,"props":269,"children":271},{"className":270},[],[272],{"type":229,"value":273},"AuthResponse",{"type":229,"value":275}," that contains the necessary Bearer token to call the 2 protected routes ",{"type":224,"tag":260,"props":277,"children":279},{"className":278},[],[280],{"type":229,"value":281},"GET /users",{"type":229,"value":283}," and ",{"type":224,"tag":260,"props":285,"children":287},{"className":286},[],[288],{"type":229,"value":289},"PUT /users/{username}",{"type":229,"value":291},".",{"type":224,"tag":225,"props":293,"children":294},{},[295],{"type":229,"value":296},"We want to implement an IUserService that has 2 methods:",{"type":224,"tag":298,"props":299,"children":300},"ul",{},[301,320],{"type":224,"tag":302,"props":303,"children":304},"li",{},[305,311,313,318],{"type":224,"tag":260,"props":306,"children":308},{"className":307},[],[309],{"type":229,"value":310},"GetAllUsers",{"type":229,"value":312}," to retrieve the list of users that will use the ",{"type":224,"tag":260,"props":314,"children":316},{"className":315},[],[317],{"type":229,"value":281},{"type":229,"value":319}," route",{"type":224,"tag":302,"props":321,"children":322},{},[323,329,331,336],{"type":224,"tag":260,"props":324,"children":326},{"className":325},[],[327],{"type":229,"value":328},"UpdateUser",{"type":229,"value":330}," to update a user that will use the ",{"type":224,"tag":260,"props":332,"children":334},{"className":333},[],[335],{"type":229,"value":289},{"type":229,"value":319},{"type":224,"tag":338,"props":339,"children":343},"pre",{"className":340,"code":341,"language":342,"meta":207,"style":207},"language-csharp shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","public interface IUserService\n{\n    Task\u003CIReadOnlyCollection\u003CUser>> GetAllUsers();\n    Task UpdateUser(User userToUpdate);\n}\n","csharp",[344],{"type":224,"tag":260,"props":345,"children":346},{"__ignoreMap":207},[347,370,380,424,456],{"type":224,"tag":348,"props":349,"children":352},"span",{"class":350,"line":351},"line",1,[353,359,365],{"type":224,"tag":348,"props":354,"children":356},{"style":355},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[357],{"type":229,"value":358},"public",{"type":224,"tag":348,"props":360,"children":362},{"style":361},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[363],{"type":229,"value":364}," interface",{"type":224,"tag":348,"props":366,"children":367},{"style":361},[368],{"type":229,"value":369}," IUserService\n",{"type":224,"tag":348,"props":371,"children":373},{"class":350,"line":372},2,[374],{"type":224,"tag":348,"props":375,"children":377},{"style":376},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[378],{"type":229,"value":379},"{\n",{"type":224,"tag":348,"props":381,"children":383},{"class":350,"line":382},3,[384,389,394,399,403,408,413,419],{"type":224,"tag":348,"props":385,"children":386},{"style":361},[387],{"type":229,"value":388},"    Task",{"type":224,"tag":348,"props":390,"children":391},{"style":376},[392],{"type":229,"value":393},"\u003C",{"type":224,"tag":348,"props":395,"children":396},{"style":361},[397],{"type":229,"value":398},"IReadOnlyCollection",{"type":224,"tag":348,"props":400,"children":401},{"style":376},[402],{"type":229,"value":393},{"type":224,"tag":348,"props":404,"children":405},{"style":361},[406],{"type":229,"value":407},"User",{"type":224,"tag":348,"props":409,"children":410},{"style":376},[411],{"type":229,"value":412},">>",{"type":224,"tag":348,"props":414,"children":416},{"style":415},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[417],{"type":229,"value":418}," GetAllUsers",{"type":224,"tag":348,"props":420,"children":421},{"style":376},[422],{"type":229,"value":423},"();\n",{"type":224,"tag":348,"props":425,"children":427},{"class":350,"line":426},4,[428,432,437,442,446,451],{"type":224,"tag":348,"props":429,"children":430},{"style":361},[431],{"type":229,"value":388},{"type":224,"tag":348,"props":433,"children":434},{"style":415},[435],{"type":229,"value":436}," UpdateUser",{"type":224,"tag":348,"props":438,"children":439},{"style":376},[440],{"type":229,"value":441},"(",{"type":224,"tag":348,"props":443,"children":444},{"style":361},[445],{"type":229,"value":407},{"type":224,"tag":348,"props":447,"children":448},{"style":361},[449],{"type":229,"value":450}," userToUpdate",{"type":224,"tag":348,"props":452,"children":453},{"style":376},[454],{"type":229,"value":455},");\n",{"type":224,"tag":348,"props":457,"children":459},{"class":350,"line":458},5,[460],{"type":224,"tag":348,"props":461,"children":462},{"style":376},[463],{"type":229,"value":464},"}\n",{"type":224,"tag":225,"props":466,"children":467},{},[468,470,475],{"type":229,"value":469},"Each of these methods needs to retrieve a valid token from the ",{"type":224,"tag":260,"props":471,"children":473},{"className":472},[],[474],{"type":229,"value":265},{"type":229,"value":476}," route and set the Authorization header with this token in the HTTP request to each of the protected routes.",{"type":224,"tag":225,"props":478,"children":479},{},[480],{"type":229,"value":481},"The following code shows how to retrieve the token:",{"type":224,"tag":338,"props":483,"children":485},{"className":340,"code":484,"language":342,"meta":207,"style":207},"var body = new { login = \"login\", password = \"password\" };\nvar response = await _httpClient.PostAsync(\"login\", new StringContent(JsonConvert.SerializeObject(body)));\nvar authResponse = await response.Content.ReadAsAsync\u003CAuthResponse>();\n",[486],{"type":224,"tag":260,"props":487,"children":488},{"__ignoreMap":207},[489,576,672],{"type":224,"tag":348,"props":490,"children":491},{"class":350,"line":351},[492,497,502,507,512,517,523,528,533,539,544,549,554,558,562,567,571],{"type":224,"tag":348,"props":493,"children":494},{"style":361},[495],{"type":229,"value":496},"var",{"type":224,"tag":348,"props":498,"children":499},{"style":361},[500],{"type":229,"value":501}," body",{"type":224,"tag":348,"props":503,"children":504},{"style":376},[505],{"type":229,"value":506}," =",{"type":224,"tag":348,"props":508,"children":509},{"style":376},[510],{"type":229,"value":511}," new",{"type":224,"tag":348,"props":513,"children":514},{"style":376},[515],{"type":229,"value":516}," {",{"type":224,"tag":348,"props":518,"children":520},{"style":519},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[521],{"type":229,"value":522}," login ",{"type":224,"tag":348,"props":524,"children":525},{"style":376},[526],{"type":229,"value":527},"=",{"type":224,"tag":348,"props":529,"children":530},{"style":376},[531],{"type":229,"value":532}," \"",{"type":224,"tag":348,"props":534,"children":536},{"style":535},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[537],{"type":229,"value":538},"login",{"type":224,"tag":348,"props":540,"children":541},{"style":376},[542],{"type":229,"value":543},"\"",{"type":224,"tag":348,"props":545,"children":546},{"style":376},[547],{"type":229,"value":548},",",{"type":224,"tag":348,"props":550,"children":551},{"style":519},[552],{"type":229,"value":553}," password ",{"type":224,"tag":348,"props":555,"children":556},{"style":376},[557],{"type":229,"value":527},{"type":224,"tag":348,"props":559,"children":560},{"style":376},[561],{"type":229,"value":532},{"type":224,"tag":348,"props":563,"children":564},{"style":535},[565],{"type":229,"value":566},"password",{"type":224,"tag":348,"props":568,"children":569},{"style":376},[570],{"type":229,"value":543},{"type":224,"tag":348,"props":572,"children":573},{"style":376},[574],{"type":229,"value":575}," };\n",{"type":224,"tag":348,"props":577,"children":578},{"class":350,"line":372},[579,583,588,592,597,602,606,611,615,619,623,627,631,635,640,644,649,653,658,662,667],{"type":224,"tag":348,"props":580,"children":581},{"style":361},[582],{"type":229,"value":496},{"type":224,"tag":348,"props":584,"children":585},{"style":361},[586],{"type":229,"value":587}," response",{"type":224,"tag":348,"props":589,"children":590},{"style":376},[591],{"type":229,"value":506},{"type":224,"tag":348,"props":593,"children":594},{"style":376},[595],{"type":229,"value":596}," await",{"type":224,"tag":348,"props":598,"children":599},{"style":519},[600],{"type":229,"value":601}," _httpClient",{"type":224,"tag":348,"props":603,"children":604},{"style":376},[605],{"type":229,"value":291},{"type":224,"tag":348,"props":607,"children":608},{"style":415},[609],{"type":229,"value":610},"PostAsync",{"type":224,"tag":348,"props":612,"children":613},{"style":376},[614],{"type":229,"value":441},{"type":224,"tag":348,"props":616,"children":617},{"style":376},[618],{"type":229,"value":543},{"type":224,"tag":348,"props":620,"children":621},{"style":535},[622],{"type":229,"value":538},{"type":224,"tag":348,"props":624,"children":625},{"style":376},[626],{"type":229,"value":543},{"type":224,"tag":348,"props":628,"children":629},{"style":376},[630],{"type":229,"value":548},{"type":224,"tag":348,"props":632,"children":633},{"style":376},[634],{"type":229,"value":511},{"type":224,"tag":348,"props":636,"children":637},{"style":361},[638],{"type":229,"value":639}," StringContent",{"type":224,"tag":348,"props":641,"children":642},{"style":376},[643],{"type":229,"value":441},{"type":224,"tag":348,"props":645,"children":646},{"style":519},[647],{"type":229,"value":648},"JsonConvert",{"type":224,"tag":348,"props":650,"children":651},{"style":376},[652],{"type":229,"value":291},{"type":224,"tag":348,"props":654,"children":655},{"style":415},[656],{"type":229,"value":657},"SerializeObject",{"type":224,"tag":348,"props":659,"children":660},{"style":376},[661],{"type":229,"value":441},{"type":224,"tag":348,"props":663,"children":664},{"style":519},[665],{"type":229,"value":666},"body",{"type":224,"tag":348,"props":668,"children":669},{"style":376},[670],{"type":229,"value":671},")));\n",{"type":224,"tag":348,"props":673,"children":674},{"class":350,"line":382},[675,679,684,688,692,696,700,705,709,714,718,722],{"type":224,"tag":348,"props":676,"children":677},{"style":361},[678],{"type":229,"value":496},{"type":224,"tag":348,"props":680,"children":681},{"style":361},[682],{"type":229,"value":683}," authResponse",{"type":224,"tag":348,"props":685,"children":686},{"style":376},[687],{"type":229,"value":506},{"type":224,"tag":348,"props":689,"children":690},{"style":376},[691],{"type":229,"value":596},{"type":224,"tag":348,"props":693,"children":694},{"style":519},[695],{"type":229,"value":587},{"type":224,"tag":348,"props":697,"children":698},{"style":376},[699],{"type":229,"value":291},{"type":224,"tag":348,"props":701,"children":702},{"style":519},[703],{"type":229,"value":704},"Content",{"type":224,"tag":348,"props":706,"children":707},{"style":376},[708],{"type":229,"value":291},{"type":224,"tag":348,"props":710,"children":711},{"style":415},[712],{"type":229,"value":713},"ReadAsAsync",{"type":224,"tag":348,"props":715,"children":716},{"style":376},[717],{"type":229,"value":393},{"type":224,"tag":348,"props":719,"children":720},{"style":361},[721],{"type":229,"value":273},{"type":224,"tag":348,"props":723,"children":724},{"style":376},[725],{"type":229,"value":726},">();\n",{"type":224,"tag":225,"props":728,"children":729},{},[730,732,737,739,744],{"type":229,"value":731},"where ",{"type":224,"tag":260,"props":733,"children":735},{"className":734},[],[736],{"type":229,"value":273},{"type":229,"value":738}," is a class we defined to map the response of the ",{"type":224,"tag":260,"props":740,"children":742},{"className":741},[],[743],{"type":229,"value":265},{"type":229,"value":319},{"type":224,"tag":338,"props":746,"children":748},{"className":340,"code":747,"language":342,"meta":207,"style":207},"public class AuthResponse\n{\n  public string Token { get; set; }\n  public DateTime Expiration { get; set; }\n}\n",[749],{"type":224,"tag":260,"props":750,"children":751},{"__ignoreMap":207},[752,769,776,822,863],{"type":224,"tag":348,"props":753,"children":754},{"class":350,"line":351},[755,759,764],{"type":224,"tag":348,"props":756,"children":757},{"style":355},[758],{"type":229,"value":358},{"type":224,"tag":348,"props":760,"children":761},{"style":361},[762],{"type":229,"value":763}," class",{"type":224,"tag":348,"props":765,"children":766},{"style":361},[767],{"type":229,"value":768}," AuthResponse\n",{"type":224,"tag":348,"props":770,"children":771},{"class":350,"line":372},[772],{"type":224,"tag":348,"props":773,"children":774},{"style":376},[775],{"type":229,"value":379},{"type":224,"tag":348,"props":777,"children":778},{"class":350,"line":382},[779,784,789,794,798,803,808,813,817],{"type":224,"tag":348,"props":780,"children":781},{"style":355},[782],{"type":229,"value":783},"  public",{"type":224,"tag":348,"props":785,"children":786},{"style":376},[787],{"type":229,"value":788}," string",{"type":224,"tag":348,"props":790,"children":791},{"style":361},[792],{"type":229,"value":793}," Token",{"type":224,"tag":348,"props":795,"children":796},{"style":376},[797],{"type":229,"value":516},{"type":224,"tag":348,"props":799,"children":800},{"style":361},[801],{"type":229,"value":802}," get",{"type":224,"tag":348,"props":804,"children":805},{"style":376},[806],{"type":229,"value":807},";",{"type":224,"tag":348,"props":809,"children":810},{"style":361},[811],{"type":229,"value":812}," set",{"type":224,"tag":348,"props":814,"children":815},{"style":376},[816],{"type":229,"value":807},{"type":224,"tag":348,"props":818,"children":819},{"style":376},[820],{"type":229,"value":821}," }\n",{"type":224,"tag":348,"props":823,"children":824},{"class":350,"line":426},[825,829,834,839,843,847,851,855,859],{"type":224,"tag":348,"props":826,"children":827},{"style":355},[828],{"type":229,"value":783},{"type":224,"tag":348,"props":830,"children":831},{"style":361},[832],{"type":229,"value":833}," DateTime",{"type":224,"tag":348,"props":835,"children":836},{"style":361},[837],{"type":229,"value":838}," Expiration",{"type":224,"tag":348,"props":840,"children":841},{"style":376},[842],{"type":229,"value":516},{"type":224,"tag":348,"props":844,"children":845},{"style":361},[846],{"type":229,"value":802},{"type":224,"tag":348,"props":848,"children":849},{"style":376},[850],{"type":229,"value":807},{"type":224,"tag":348,"props":852,"children":853},{"style":361},[854],{"type":229,"value":812},{"type":224,"tag":348,"props":856,"children":857},{"style":376},[858],{"type":229,"value":807},{"type":224,"tag":348,"props":860,"children":861},{"style":376},[862],{"type":229,"value":821},{"type":224,"tag":348,"props":864,"children":865},{"class":350,"line":458},[866],{"type":224,"tag":348,"props":867,"children":868},{"style":376},[869],{"type":229,"value":464},{"type":224,"tag":225,"props":871,"children":872},{},[873,875,881],{"type":229,"value":874},"So now we have the code to retrieve the token, how do we use it to implement our ",{"type":224,"tag":260,"props":876,"children":878},{"className":877},[],[879],{"type":229,"value":880},"IUserService",{"type":229,"value":882},"?",{"type":224,"tag":231,"props":884,"children":886},{"id":885},"retrieve-the-token-from-a-private-method",[887],{"type":229,"value":888},"Retrieve the token from a private method",{"type":224,"tag":225,"props":890,"children":891},{},[892,894,900,902,907,908,913],{"type":229,"value":893},"The easiest way to do that is to create a private method in ",{"type":224,"tag":260,"props":895,"children":897},{"className":896},[],[898],{"type":229,"value":899},"UserService",{"type":229,"value":901}," that returns this token and to call it from ",{"type":224,"tag":260,"props":903,"children":905},{"className":904},[],[906],{"type":229,"value":310},{"type":229,"value":283},{"type":224,"tag":260,"props":909,"children":911},{"className":910},[],[912],{"type":229,"value":328},{"type":229,"value":914},". That would give us something like that :",{"type":224,"tag":338,"props":916,"children":918},{"className":340,"code":917,"language":342,"meta":207,"style":207},"public class UserService : IUserService\n{\n    private readonly HttpClient _httpClient;\n    public UserService(HttpClient httpClient)\n    {\n        _httpClient = httpClient;\n    }\n\n    public async Task\u003CIReadOnlyCollection\u003CUser>> GetAllUsers()\n    {\n        var token = await RetrieveToken();\n        var request = new HttpRequestMessage(HttpMethod.Get, \"user\");\n        request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", token);\n        var response = await _httpClient.SendAsync(request);\n        response.EnsureSuccessStatusCode();\n        return await response.Content.ReadAsAsync\u003CIReadOnlyCollection\u003CUser>>();\n    }\n\n    public async Task UpdateUser(User userToUpdate)\n    {\n        var token = await RetrieveToken();\n        var request = new HttpRequestMessage(HttpMethod.Put, $\"user/{userToUpdate.Name}\");\n        request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", token);\n        request.Content = new StringContent(JsonConvert.SerializeObject(userToUpdate));\n        var response = await _httpClient.SendAsync(request);\n        response.EnsureSuccessStatusCode();\n    }\n\n    private async Task\u003Cstring> RetrieveToken()\n    {\n        var body = new { login = \"login\", password = \"password\" };\n        var response = await _httpClient.PostAsync(\"login\", new StringContent(JsonConvert.SerializeObject(body)));\n        var authResponse = await response.Content.ReadAsAsync\u003CAuthResponse>();\n        return authResponse.Token;\n    }\n}\n",[919],{"type":224,"tag":260,"props":920,"children":921},{"__ignoreMap":207},[922,947,954,981,1012,1020,1041,1050,1060,1107,1115,1146,1211,1280,1326,1348,1403,1411,1419,1455,1463,1491,1574,1638,1696,1740,1760,1768,1776,1814,1822,1894,1982,2034,2059,2067],{"type":224,"tag":348,"props":923,"children":924},{"class":350,"line":351},[925,929,933,938,943],{"type":224,"tag":348,"props":926,"children":927},{"style":355},[928],{"type":229,"value":358},{"type":224,"tag":348,"props":930,"children":931},{"style":361},[932],{"type":229,"value":763},{"type":224,"tag":348,"props":934,"children":935},{"style":361},[936],{"type":229,"value":937}," UserService",{"type":224,"tag":348,"props":939,"children":940},{"style":376},[941],{"type":229,"value":942}," :",{"type":224,"tag":348,"props":944,"children":945},{"style":361},[946],{"type":229,"value":369},{"type":224,"tag":348,"props":948,"children":949},{"class":350,"line":372},[950],{"type":224,"tag":348,"props":951,"children":952},{"style":376},[953],{"type":229,"value":379},{"type":224,"tag":348,"props":955,"children":956},{"class":350,"line":382},[957,962,967,972,976],{"type":224,"tag":348,"props":958,"children":959},{"style":355},[960],{"type":229,"value":961},"    private",{"type":224,"tag":348,"props":963,"children":964},{"style":355},[965],{"type":229,"value":966}," readonly",{"type":224,"tag":348,"props":968,"children":969},{"style":361},[970],{"type":229,"value":971}," HttpClient",{"type":224,"tag":348,"props":973,"children":974},{"style":361},[975],{"type":229,"value":601},{"type":224,"tag":348,"props":977,"children":978},{"style":376},[979],{"type":229,"value":980},";\n",{"type":224,"tag":348,"props":982,"children":983},{"class":350,"line":426},[984,989,993,997,1002,1007],{"type":224,"tag":348,"props":985,"children":986},{"style":355},[987],{"type":229,"value":988},"    public",{"type":224,"tag":348,"props":990,"children":991},{"style":415},[992],{"type":229,"value":937},{"type":224,"tag":348,"props":994,"children":995},{"style":376},[996],{"type":229,"value":441},{"type":224,"tag":348,"props":998,"children":999},{"style":361},[1000],{"type":229,"value":1001},"HttpClient",{"type":224,"tag":348,"props":1003,"children":1004},{"style":361},[1005],{"type":229,"value":1006}," httpClient",{"type":224,"tag":348,"props":1008,"children":1009},{"style":376},[1010],{"type":229,"value":1011},")\n",{"type":224,"tag":348,"props":1013,"children":1014},{"class":350,"line":458},[1015],{"type":224,"tag":348,"props":1016,"children":1017},{"style":376},[1018],{"type":229,"value":1019},"    {\n",{"type":224,"tag":348,"props":1021,"children":1023},{"class":350,"line":1022},6,[1024,1029,1033,1037],{"type":224,"tag":348,"props":1025,"children":1026},{"style":519},[1027],{"type":229,"value":1028},"        _httpClient ",{"type":224,"tag":348,"props":1030,"children":1031},{"style":376},[1032],{"type":229,"value":527},{"type":224,"tag":348,"props":1034,"children":1035},{"style":519},[1036],{"type":229,"value":1006},{"type":224,"tag":348,"props":1038,"children":1039},{"style":376},[1040],{"type":229,"value":980},{"type":224,"tag":348,"props":1042,"children":1044},{"class":350,"line":1043},7,[1045],{"type":224,"tag":348,"props":1046,"children":1047},{"style":376},[1048],{"type":229,"value":1049},"    }\n",{"type":224,"tag":348,"props":1051,"children":1053},{"class":350,"line":1052},8,[1054],{"type":224,"tag":348,"props":1055,"children":1057},{"emptyLinePlaceholder":1056},true,[1058],{"type":229,"value":1059},"\n",{"type":224,"tag":348,"props":1061,"children":1063},{"class":350,"line":1062},9,[1064,1068,1073,1078,1082,1086,1090,1094,1098,1102],{"type":224,"tag":348,"props":1065,"children":1066},{"style":355},[1067],{"type":229,"value":988},{"type":224,"tag":348,"props":1069,"children":1070},{"style":355},[1071],{"type":229,"value":1072}," async",{"type":224,"tag":348,"props":1074,"children":1075},{"style":361},[1076],{"type":229,"value":1077}," Task",{"type":224,"tag":348,"props":1079,"children":1080},{"style":376},[1081],{"type":229,"value":393},{"type":224,"tag":348,"props":1083,"children":1084},{"style":361},[1085],{"type":229,"value":398},{"type":224,"tag":348,"props":1087,"children":1088},{"style":376},[1089],{"type":229,"value":393},{"type":224,"tag":348,"props":1091,"children":1092},{"style":361},[1093],{"type":229,"value":407},{"type":224,"tag":348,"props":1095,"children":1096},{"style":376},[1097],{"type":229,"value":412},{"type":224,"tag":348,"props":1099,"children":1100},{"style":415},[1101],{"type":229,"value":418},{"type":224,"tag":348,"props":1103,"children":1104},{"style":376},[1105],{"type":229,"value":1106},"()\n",{"type":224,"tag":348,"props":1108,"children":1110},{"class":350,"line":1109},10,[1111],{"type":224,"tag":348,"props":1112,"children":1113},{"style":376},[1114],{"type":229,"value":1019},{"type":224,"tag":348,"props":1116,"children":1118},{"class":350,"line":1117},11,[1119,1124,1129,1133,1137,1142],{"type":224,"tag":348,"props":1120,"children":1121},{"style":361},[1122],{"type":229,"value":1123},"        var",{"type":224,"tag":348,"props":1125,"children":1126},{"style":361},[1127],{"type":229,"value":1128}," token",{"type":224,"tag":348,"props":1130,"children":1131},{"style":376},[1132],{"type":229,"value":506},{"type":224,"tag":348,"props":1134,"children":1135},{"style":376},[1136],{"type":229,"value":596},{"type":224,"tag":348,"props":1138,"children":1139},{"style":415},[1140],{"type":229,"value":1141}," RetrieveToken",{"type":224,"tag":348,"props":1143,"children":1144},{"style":376},[1145],{"type":229,"value":423},{"type":224,"tag":348,"props":1147,"children":1149},{"class":350,"line":1148},12,[1150,1154,1159,1163,1167,1172,1176,1181,1185,1190,1194,1198,1203,1207],{"type":224,"tag":348,"props":1151,"children":1152},{"style":361},[1153],{"type":229,"value":1123},{"type":224,"tag":348,"props":1155,"children":1156},{"style":361},[1157],{"type":229,"value":1158}," request",{"type":224,"tag":348,"props":1160,"children":1161},{"style":376},[1162],{"type":229,"value":506},{"type":224,"tag":348,"props":1164,"children":1165},{"style":376},[1166],{"type":229,"value":511},{"type":224,"tag":348,"props":1168,"children":1169},{"style":361},[1170],{"type":229,"value":1171}," HttpRequestMessage",{"type":224,"tag":348,"props":1173,"children":1174},{"style":376},[1175],{"type":229,"value":441},{"type":224,"tag":348,"props":1177,"children":1178},{"style":519},[1179],{"type":229,"value":1180},"HttpMethod",{"type":224,"tag":348,"props":1182,"children":1183},{"style":376},[1184],{"type":229,"value":291},{"type":224,"tag":348,"props":1186,"children":1187},{"style":519},[1188],{"type":229,"value":1189},"Get",{"type":224,"tag":348,"props":1191,"children":1192},{"style":376},[1193],{"type":229,"value":548},{"type":224,"tag":348,"props":1195,"children":1196},{"style":376},[1197],{"type":229,"value":532},{"type":224,"tag":348,"props":1199,"children":1200},{"style":535},[1201],{"type":229,"value":1202},"user",{"type":224,"tag":348,"props":1204,"children":1205},{"style":376},[1206],{"type":229,"value":543},{"type":224,"tag":348,"props":1208,"children":1209},{"style":376},[1210],{"type":229,"value":455},{"type":224,"tag":348,"props":1212,"children":1214},{"class":350,"line":1213},13,[1215,1220,1224,1229,1233,1238,1242,1246,1251,1255,1259,1264,1268,1272,1276],{"type":224,"tag":348,"props":1216,"children":1217},{"style":519},[1218],{"type":229,"value":1219},"        request",{"type":224,"tag":348,"props":1221,"children":1222},{"style":376},[1223],{"type":229,"value":291},{"type":224,"tag":348,"props":1225,"children":1226},{"style":519},[1227],{"type":229,"value":1228},"Headers",{"type":224,"tag":348,"props":1230,"children":1231},{"style":376},[1232],{"type":229,"value":291},{"type":224,"tag":348,"props":1234,"children":1235},{"style":519},[1236],{"type":229,"value":1237},"Authorization ",{"type":224,"tag":348,"props":1239,"children":1240},{"style":376},[1241],{"type":229,"value":527},{"type":224,"tag":348,"props":1243,"children":1244},{"style":376},[1245],{"type":229,"value":511},{"type":224,"tag":348,"props":1247,"children":1248},{"style":361},[1249],{"type":229,"value":1250}," AuthenticationHeaderValue",{"type":224,"tag":348,"props":1252,"children":1253},{"style":376},[1254],{"type":229,"value":441},{"type":224,"tag":348,"props":1256,"children":1257},{"style":376},[1258],{"type":229,"value":543},{"type":224,"tag":348,"props":1260,"children":1261},{"style":535},[1262],{"type":229,"value":1263},"Bearer",{"type":224,"tag":348,"props":1265,"children":1266},{"style":376},[1267],{"type":229,"value":543},{"type":224,"tag":348,"props":1269,"children":1270},{"style":376},[1271],{"type":229,"value":548},{"type":224,"tag":348,"props":1273,"children":1274},{"style":519},[1275],{"type":229,"value":1128},{"type":224,"tag":348,"props":1277,"children":1278},{"style":376},[1279],{"type":229,"value":455},{"type":224,"tag":348,"props":1281,"children":1283},{"class":350,"line":1282},14,[1284,1288,1292,1296,1300,1304,1308,1313,1317,1322],{"type":224,"tag":348,"props":1285,"children":1286},{"style":361},[1287],{"type":229,"value":1123},{"type":224,"tag":348,"props":1289,"children":1290},{"style":361},[1291],{"type":229,"value":587},{"type":224,"tag":348,"props":1293,"children":1294},{"style":376},[1295],{"type":229,"value":506},{"type":224,"tag":348,"props":1297,"children":1298},{"style":376},[1299],{"type":229,"value":596},{"type":224,"tag":348,"props":1301,"children":1302},{"style":519},[1303],{"type":229,"value":601},{"type":224,"tag":348,"props":1305,"children":1306},{"style":376},[1307],{"type":229,"value":291},{"type":224,"tag":348,"props":1309,"children":1310},{"style":415},[1311],{"type":229,"value":1312},"SendAsync",{"type":224,"tag":348,"props":1314,"children":1315},{"style":376},[1316],{"type":229,"value":441},{"type":224,"tag":348,"props":1318,"children":1319},{"style":519},[1320],{"type":229,"value":1321},"request",{"type":224,"tag":348,"props":1323,"children":1324},{"style":376},[1325],{"type":229,"value":455},{"type":224,"tag":348,"props":1327,"children":1329},{"class":350,"line":1328},15,[1330,1335,1339,1344],{"type":224,"tag":348,"props":1331,"children":1332},{"style":519},[1333],{"type":229,"value":1334},"        response",{"type":224,"tag":348,"props":1336,"children":1337},{"style":376},[1338],{"type":229,"value":291},{"type":224,"tag":348,"props":1340,"children":1341},{"style":415},[1342],{"type":229,"value":1343},"EnsureSuccessStatusCode",{"type":224,"tag":348,"props":1345,"children":1346},{"style":376},[1347],{"type":229,"value":423},{"type":224,"tag":348,"props":1349,"children":1351},{"class":350,"line":1350},16,[1352,1358,1362,1366,1370,1374,1378,1382,1386,1390,1394,1398],{"type":224,"tag":348,"props":1353,"children":1355},{"style":1354},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF;--shiki-light-font-style:italic;--shiki-default-font-style:italic;--shiki-dark-font-style:italic",[1356],{"type":229,"value":1357},"        return",{"type":224,"tag":348,"props":1359,"children":1360},{"style":376},[1361],{"type":229,"value":596},{"type":224,"tag":348,"props":1363,"children":1364},{"style":519},[1365],{"type":229,"value":587},{"type":224,"tag":348,"props":1367,"children":1368},{"style":376},[1369],{"type":229,"value":291},{"type":224,"tag":348,"props":1371,"children":1372},{"style":519},[1373],{"type":229,"value":704},{"type":224,"tag":348,"props":1375,"children":1376},{"style":376},[1377],{"type":229,"value":291},{"type":224,"tag":348,"props":1379,"children":1380},{"style":415},[1381],{"type":229,"value":713},{"type":224,"tag":348,"props":1383,"children":1384},{"style":376},[1385],{"type":229,"value":393},{"type":224,"tag":348,"props":1387,"children":1388},{"style":361},[1389],{"type":229,"value":398},{"type":224,"tag":348,"props":1391,"children":1392},{"style":376},[1393],{"type":229,"value":393},{"type":224,"tag":348,"props":1395,"children":1396},{"style":361},[1397],{"type":229,"value":407},{"type":224,"tag":348,"props":1399,"children":1400},{"style":376},[1401],{"type":229,"value":1402},">>();\n",{"type":224,"tag":348,"props":1404,"children":1406},{"class":350,"line":1405},17,[1407],{"type":224,"tag":348,"props":1408,"children":1409},{"style":376},[1410],{"type":229,"value":1049},{"type":224,"tag":348,"props":1412,"children":1414},{"class":350,"line":1413},18,[1415],{"type":224,"tag":348,"props":1416,"children":1417},{"emptyLinePlaceholder":1056},[1418],{"type":229,"value":1059},{"type":224,"tag":348,"props":1420,"children":1422},{"class":350,"line":1421},19,[1423,1427,1431,1435,1439,1443,1447,1451],{"type":224,"tag":348,"props":1424,"children":1425},{"style":355},[1426],{"type":229,"value":988},{"type":224,"tag":348,"props":1428,"children":1429},{"style":355},[1430],{"type":229,"value":1072},{"type":224,"tag":348,"props":1432,"children":1433},{"style":361},[1434],{"type":229,"value":1077},{"type":224,"tag":348,"props":1436,"children":1437},{"style":415},[1438],{"type":229,"value":436},{"type":224,"tag":348,"props":1440,"children":1441},{"style":376},[1442],{"type":229,"value":441},{"type":224,"tag":348,"props":1444,"children":1445},{"style":361},[1446],{"type":229,"value":407},{"type":224,"tag":348,"props":1448,"children":1449},{"style":361},[1450],{"type":229,"value":450},{"type":224,"tag":348,"props":1452,"children":1453},{"style":376},[1454],{"type":229,"value":1011},{"type":224,"tag":348,"props":1456,"children":1458},{"class":350,"line":1457},20,[1459],{"type":224,"tag":348,"props":1460,"children":1461},{"style":376},[1462],{"type":229,"value":1019},{"type":224,"tag":348,"props":1464,"children":1466},{"class":350,"line":1465},21,[1467,1471,1475,1479,1483,1487],{"type":224,"tag":348,"props":1468,"children":1469},{"style":361},[1470],{"type":229,"value":1123},{"type":224,"tag":348,"props":1472,"children":1473},{"style":361},[1474],{"type":229,"value":1128},{"type":224,"tag":348,"props":1476,"children":1477},{"style":376},[1478],{"type":229,"value":506},{"type":224,"tag":348,"props":1480,"children":1481},{"style":376},[1482],{"type":229,"value":596},{"type":224,"tag":348,"props":1484,"children":1485},{"style":415},[1486],{"type":229,"value":1141},{"type":224,"tag":348,"props":1488,"children":1489},{"style":376},[1490],{"type":229,"value":423},{"type":224,"tag":348,"props":1492,"children":1494},{"class":350,"line":1493},22,[1495,1499,1503,1507,1511,1515,1519,1523,1527,1532,1536,1541,1546,1551,1556,1560,1565,1570],{"type":224,"tag":348,"props":1496,"children":1497},{"style":361},[1498],{"type":229,"value":1123},{"type":224,"tag":348,"props":1500,"children":1501},{"style":361},[1502],{"type":229,"value":1158},{"type":224,"tag":348,"props":1504,"children":1505},{"style":376},[1506],{"type":229,"value":506},{"type":224,"tag":348,"props":1508,"children":1509},{"style":376},[1510],{"type":229,"value":511},{"type":224,"tag":348,"props":1512,"children":1513},{"style":361},[1514],{"type":229,"value":1171},{"type":224,"tag":348,"props":1516,"children":1517},{"style":376},[1518],{"type":229,"value":441},{"type":224,"tag":348,"props":1520,"children":1521},{"style":519},[1522],{"type":229,"value":1180},{"type":224,"tag":348,"props":1524,"children":1525},{"style":376},[1526],{"type":229,"value":291},{"type":224,"tag":348,"props":1528,"children":1529},{"style":519},[1530],{"type":229,"value":1531},"Put",{"type":224,"tag":348,"props":1533,"children":1534},{"style":376},[1535],{"type":229,"value":548},{"type":224,"tag":348,"props":1537,"children":1538},{"style":376},[1539],{"type":229,"value":1540}," $\"",{"type":224,"tag":348,"props":1542,"children":1543},{"style":535},[1544],{"type":229,"value":1545},"user/",{"type":224,"tag":348,"props":1547,"children":1548},{"style":376},[1549],{"type":229,"value":1550},"{",{"type":224,"tag":348,"props":1552,"children":1553},{"style":519},[1554],{"type":229,"value":1555},"userToUpdate",{"type":224,"tag":348,"props":1557,"children":1558},{"style":376},[1559],{"type":229,"value":291},{"type":224,"tag":348,"props":1561,"children":1562},{"style":519},[1563],{"type":229,"value":1564},"Name",{"type":224,"tag":348,"props":1566,"children":1567},{"style":376},[1568],{"type":229,"value":1569},"}\"",{"type":224,"tag":348,"props":1571,"children":1572},{"style":376},[1573],{"type":229,"value":455},{"type":224,"tag":348,"props":1575,"children":1577},{"class":350,"line":1576},23,[1578,1582,1586,1590,1594,1598,1602,1606,1610,1614,1618,1622,1626,1630,1634],{"type":224,"tag":348,"props":1579,"children":1580},{"style":519},[1581],{"type":229,"value":1219},{"type":224,"tag":348,"props":1583,"children":1584},{"style":376},[1585],{"type":229,"value":291},{"type":224,"tag":348,"props":1587,"children":1588},{"style":519},[1589],{"type":229,"value":1228},{"type":224,"tag":348,"props":1591,"children":1592},{"style":376},[1593],{"type":229,"value":291},{"type":224,"tag":348,"props":1595,"children":1596},{"style":519},[1597],{"type":229,"value":1237},{"type":224,"tag":348,"props":1599,"children":1600},{"style":376},[1601],{"type":229,"value":527},{"type":224,"tag":348,"props":1603,"children":1604},{"style":376},[1605],{"type":229,"value":511},{"type":224,"tag":348,"props":1607,"children":1608},{"style":361},[1609],{"type":229,"value":1250},{"type":224,"tag":348,"props":1611,"children":1612},{"style":376},[1613],{"type":229,"value":441},{"type":224,"tag":348,"props":1615,"children":1616},{"style":376},[1617],{"type":229,"value":543},{"type":224,"tag":348,"props":1619,"children":1620},{"style":535},[1621],{"type":229,"value":1263},{"type":224,"tag":348,"props":1623,"children":1624},{"style":376},[1625],{"type":229,"value":543},{"type":224,"tag":348,"props":1627,"children":1628},{"style":376},[1629],{"type":229,"value":548},{"type":224,"tag":348,"props":1631,"children":1632},{"style":519},[1633],{"type":229,"value":1128},{"type":224,"tag":348,"props":1635,"children":1636},{"style":376},[1637],{"type":229,"value":455},{"type":224,"tag":348,"props":1639,"children":1641},{"class":350,"line":1640},24,[1642,1646,1650,1655,1659,1663,1667,1671,1675,1679,1683,1687,1691],{"type":224,"tag":348,"props":1643,"children":1644},{"style":519},[1645],{"type":229,"value":1219},{"type":224,"tag":348,"props":1647,"children":1648},{"style":376},[1649],{"type":229,"value":291},{"type":224,"tag":348,"props":1651,"children":1652},{"style":519},[1653],{"type":229,"value":1654},"Content ",{"type":224,"tag":348,"props":1656,"children":1657},{"style":376},[1658],{"type":229,"value":527},{"type":224,"tag":348,"props":1660,"children":1661},{"style":376},[1662],{"type":229,"value":511},{"type":224,"tag":348,"props":1664,"children":1665},{"style":361},[1666],{"type":229,"value":639},{"type":224,"tag":348,"props":1668,"children":1669},{"style":376},[1670],{"type":229,"value":441},{"type":224,"tag":348,"props":1672,"children":1673},{"style":519},[1674],{"type":229,"value":648},{"type":224,"tag":348,"props":1676,"children":1677},{"style":376},[1678],{"type":229,"value":291},{"type":224,"tag":348,"props":1680,"children":1681},{"style":415},[1682],{"type":229,"value":657},{"type":224,"tag":348,"props":1684,"children":1685},{"style":376},[1686],{"type":229,"value":441},{"type":224,"tag":348,"props":1688,"children":1689},{"style":519},[1690],{"type":229,"value":1555},{"type":224,"tag":348,"props":1692,"children":1693},{"style":376},[1694],{"type":229,"value":1695},"));\n",{"type":224,"tag":348,"props":1697,"children":1699},{"class":350,"line":1698},25,[1700,1704,1708,1712,1716,1720,1724,1728,1732,1736],{"type":224,"tag":348,"props":1701,"children":1702},{"style":361},[1703],{"type":229,"value":1123},{"type":224,"tag":348,"props":1705,"children":1706},{"style":361},[1707],{"type":229,"value":587},{"type":224,"tag":348,"props":1709,"children":1710},{"style":376},[1711],{"type":229,"value":506},{"type":224,"tag":348,"props":1713,"children":1714},{"style":376},[1715],{"type":229,"value":596},{"type":224,"tag":348,"props":1717,"children":1718},{"style":519},[1719],{"type":229,"value":601},{"type":224,"tag":348,"props":1721,"children":1722},{"style":376},[1723],{"type":229,"value":291},{"type":224,"tag":348,"props":1725,"children":1726},{"style":415},[1727],{"type":229,"value":1312},{"type":224,"tag":348,"props":1729,"children":1730},{"style":376},[1731],{"type":229,"value":441},{"type":224,"tag":348,"props":1733,"children":1734},{"style":519},[1735],{"type":229,"value":1321},{"type":224,"tag":348,"props":1737,"children":1738},{"style":376},[1739],{"type":229,"value":455},{"type":224,"tag":348,"props":1741,"children":1743},{"class":350,"line":1742},26,[1744,1748,1752,1756],{"type":224,"tag":348,"props":1745,"children":1746},{"style":519},[1747],{"type":229,"value":1334},{"type":224,"tag":348,"props":1749,"children":1750},{"style":376},[1751],{"type":229,"value":291},{"type":224,"tag":348,"props":1753,"children":1754},{"style":415},[1755],{"type":229,"value":1343},{"type":224,"tag":348,"props":1757,"children":1758},{"style":376},[1759],{"type":229,"value":423},{"type":224,"tag":348,"props":1761,"children":1763},{"class":350,"line":1762},27,[1764],{"type":224,"tag":348,"props":1765,"children":1766},{"style":376},[1767],{"type":229,"value":1049},{"type":224,"tag":348,"props":1769,"children":1771},{"class":350,"line":1770},28,[1772],{"type":224,"tag":348,"props":1773,"children":1774},{"emptyLinePlaceholder":1056},[1775],{"type":229,"value":1059},{"type":224,"tag":348,"props":1777,"children":1779},{"class":350,"line":1778},29,[1780,1784,1788,1792,1796,1801,1806,1810],{"type":224,"tag":348,"props":1781,"children":1782},{"style":355},[1783],{"type":229,"value":961},{"type":224,"tag":348,"props":1785,"children":1786},{"style":355},[1787],{"type":229,"value":1072},{"type":224,"tag":348,"props":1789,"children":1790},{"style":361},[1791],{"type":229,"value":1077},{"type":224,"tag":348,"props":1793,"children":1794},{"style":376},[1795],{"type":229,"value":393},{"type":224,"tag":348,"props":1797,"children":1798},{"style":376},[1799],{"type":229,"value":1800},"string",{"type":224,"tag":348,"props":1802,"children":1803},{"style":376},[1804],{"type":229,"value":1805},">",{"type":224,"tag":348,"props":1807,"children":1808},{"style":415},[1809],{"type":229,"value":1141},{"type":224,"tag":348,"props":1811,"children":1812},{"style":376},[1813],{"type":229,"value":1106},{"type":224,"tag":348,"props":1815,"children":1817},{"class":350,"line":1816},30,[1818],{"type":224,"tag":348,"props":1819,"children":1820},{"style":376},[1821],{"type":229,"value":1019},{"type":224,"tag":348,"props":1823,"children":1825},{"class":350,"line":1824},31,[1826,1830,1834,1838,1842,1846,1850,1854,1858,1862,1866,1870,1874,1878,1882,1886,1890],{"type":224,"tag":348,"props":1827,"children":1828},{"style":361},[1829],{"type":229,"value":1123},{"type":224,"tag":348,"props":1831,"children":1832},{"style":361},[1833],{"type":229,"value":501},{"type":224,"tag":348,"props":1835,"children":1836},{"style":376},[1837],{"type":229,"value":506},{"type":224,"tag":348,"props":1839,"children":1840},{"style":376},[1841],{"type":229,"value":511},{"type":224,"tag":348,"props":1843,"children":1844},{"style":376},[1845],{"type":229,"value":516},{"type":224,"tag":348,"props":1847,"children":1848},{"style":519},[1849],{"type":229,"value":522},{"type":224,"tag":348,"props":1851,"children":1852},{"style":376},[1853],{"type":229,"value":527},{"type":224,"tag":348,"props":1855,"children":1856},{"style":376},[1857],{"type":229,"value":532},{"type":224,"tag":348,"props":1859,"children":1860},{"style":535},[1861],{"type":229,"value":538},{"type":224,"tag":348,"props":1863,"children":1864},{"style":376},[1865],{"type":229,"value":543},{"type":224,"tag":348,"props":1867,"children":1868},{"style":376},[1869],{"type":229,"value":548},{"type":224,"tag":348,"props":1871,"children":1872},{"style":519},[1873],{"type":229,"value":553},{"type":224,"tag":348,"props":1875,"children":1876},{"style":376},[1877],{"type":229,"value":527},{"type":224,"tag":348,"props":1879,"children":1880},{"style":376},[1881],{"type":229,"value":532},{"type":224,"tag":348,"props":1883,"children":1884},{"style":535},[1885],{"type":229,"value":566},{"type":224,"tag":348,"props":1887,"children":1888},{"style":376},[1889],{"type":229,"value":543},{"type":224,"tag":348,"props":1891,"children":1892},{"style":376},[1893],{"type":229,"value":575},{"type":224,"tag":348,"props":1895,"children":1897},{"class":350,"line":1896},32,[1898,1902,1906,1910,1914,1918,1922,1926,1930,1934,1938,1942,1946,1950,1954,1958,1962,1966,1970,1974,1978],{"type":224,"tag":348,"props":1899,"children":1900},{"style":361},[1901],{"type":229,"value":1123},{"type":224,"tag":348,"props":1903,"children":1904},{"style":361},[1905],{"type":229,"value":587},{"type":224,"tag":348,"props":1907,"children":1908},{"style":376},[1909],{"type":229,"value":506},{"type":224,"tag":348,"props":1911,"children":1912},{"style":376},[1913],{"type":229,"value":596},{"type":224,"tag":348,"props":1915,"children":1916},{"style":519},[1917],{"type":229,"value":601},{"type":224,"tag":348,"props":1919,"children":1920},{"style":376},[1921],{"type":229,"value":291},{"type":224,"tag":348,"props":1923,"children":1924},{"style":415},[1925],{"type":229,"value":610},{"type":224,"tag":348,"props":1927,"children":1928},{"style":376},[1929],{"type":229,"value":441},{"type":224,"tag":348,"props":1931,"children":1932},{"style":376},[1933],{"type":229,"value":543},{"type":224,"tag":348,"props":1935,"children":1936},{"style":535},[1937],{"type":229,"value":538},{"type":224,"tag":348,"props":1939,"children":1940},{"style":376},[1941],{"type":229,"value":543},{"type":224,"tag":348,"props":1943,"children":1944},{"style":376},[1945],{"type":229,"value":548},{"type":224,"tag":348,"props":1947,"children":1948},{"style":376},[1949],{"type":229,"value":511},{"type":224,"tag":348,"props":1951,"children":1952},{"style":361},[1953],{"type":229,"value":639},{"type":224,"tag":348,"props":1955,"children":1956},{"style":376},[1957],{"type":229,"value":441},{"type":224,"tag":348,"props":1959,"children":1960},{"style":519},[1961],{"type":229,"value":648},{"type":224,"tag":348,"props":1963,"children":1964},{"style":376},[1965],{"type":229,"value":291},{"type":224,"tag":348,"props":1967,"children":1968},{"style":415},[1969],{"type":229,"value":657},{"type":224,"tag":348,"props":1971,"children":1972},{"style":376},[1973],{"type":229,"value":441},{"type":224,"tag":348,"props":1975,"children":1976},{"style":519},[1977],{"type":229,"value":666},{"type":224,"tag":348,"props":1979,"children":1980},{"style":376},[1981],{"type":229,"value":671},{"type":224,"tag":348,"props":1983,"children":1985},{"class":350,"line":1984},33,[1986,1990,1994,1998,2002,2006,2010,2014,2018,2022,2026,2030],{"type":224,"tag":348,"props":1987,"children":1988},{"style":361},[1989],{"type":229,"value":1123},{"type":224,"tag":348,"props":1991,"children":1992},{"style":361},[1993],{"type":229,"value":683},{"type":224,"tag":348,"props":1995,"children":1996},{"style":376},[1997],{"type":229,"value":506},{"type":224,"tag":348,"props":1999,"children":2000},{"style":376},[2001],{"type":229,"value":596},{"type":224,"tag":348,"props":2003,"children":2004},{"style":519},[2005],{"type":229,"value":587},{"type":224,"tag":348,"props":2007,"children":2008},{"style":376},[2009],{"type":229,"value":291},{"type":224,"tag":348,"props":2011,"children":2012},{"style":519},[2013],{"type":229,"value":704},{"type":224,"tag":348,"props":2015,"children":2016},{"style":376},[2017],{"type":229,"value":291},{"type":224,"tag":348,"props":2019,"children":2020},{"style":415},[2021],{"type":229,"value":713},{"type":224,"tag":348,"props":2023,"children":2024},{"style":376},[2025],{"type":229,"value":393},{"type":224,"tag":348,"props":2027,"children":2028},{"style":361},[2029],{"type":229,"value":273},{"type":224,"tag":348,"props":2031,"children":2032},{"style":376},[2033],{"type":229,"value":726},{"type":224,"tag":348,"props":2035,"children":2037},{"class":350,"line":2036},34,[2038,2042,2046,2050,2055],{"type":224,"tag":348,"props":2039,"children":2040},{"style":1354},[2041],{"type":229,"value":1357},{"type":224,"tag":348,"props":2043,"children":2044},{"style":519},[2045],{"type":229,"value":683},{"type":224,"tag":348,"props":2047,"children":2048},{"style":376},[2049],{"type":229,"value":291},{"type":224,"tag":348,"props":2051,"children":2052},{"style":519},[2053],{"type":229,"value":2054},"Token",{"type":224,"tag":348,"props":2056,"children":2057},{"style":376},[2058],{"type":229,"value":980},{"type":224,"tag":348,"props":2060,"children":2062},{"class":350,"line":2061},35,[2063],{"type":224,"tag":348,"props":2064,"children":2065},{"style":376},[2066],{"type":229,"value":1049},{"type":224,"tag":348,"props":2068,"children":2070},{"class":350,"line":2069},36,[2071],{"type":224,"tag":348,"props":2072,"children":2073},{"style":376},[2074],{"type":229,"value":464},{"type":224,"tag":225,"props":2076,"children":2077},{},[2078],{"type":229,"value":2079},"There are two main problems with this way of doing things:",{"type":224,"tag":298,"props":2081,"children":2082},{},[2083,2103],{"type":224,"tag":302,"props":2084,"children":2085},{},[2086,2088,2094,2096,2101],{"type":229,"value":2087},"We have some code duplication as we are calling the ",{"type":224,"tag":260,"props":2089,"children":2091},{"className":2090},[],[2092],{"type":229,"value":2093},"RetrieveToken",{"type":229,"value":2095}," in each of our methods calling the API. That could be okay here as we only have 2 methods calling the API but that can quickly be problematic if we start to have more methods and repeat the call to ",{"type":224,"tag":260,"props":2097,"children":2099},{"className":2098},[],[2100],{"type":229,"value":2093},{"type":229,"value":2102},"in each method.",{"type":224,"tag":302,"props":2104,"children":2105},{},[2106,2108,2113],{"type":229,"value":2107},"For each call to an authenticated route of the API, we are making a call to the ",{"type":224,"tag":260,"props":2109,"children":2111},{"className":2110},[],[2112],{"type":229,"value":538},{"type":229,"value":2114}," route even if our token from a previous call is probably still valid.",{"type":224,"tag":231,"props":2116,"children":2118},{"id":2117},"use-a-dedicated-service-to-retrieve-the-token-and-save-it-for-future-calls",[2119],{"type":229,"value":2120},"Use a dedicated service to retrieve the token and save it for future calls",{"type":224,"tag":225,"props":2122,"children":2123},{},[2124,2126,2131,2133,2139,2141,2146,2148,2153,2155,2160],{"type":229,"value":2125},"Although it's not necessary at this point, it can be interesting to move the code of our private method ",{"type":224,"tag":260,"props":2127,"children":2129},{"className":2128},[],[2130],{"type":229,"value":2093},{"type":229,"value":2132}," into a separate service ",{"type":224,"tag":260,"props":2134,"children":2136},{"className":2135},[],[2137],{"type":229,"value":2138},"UserApiAuthenticationService",{"type":229,"value":2140}," that will be injected in ",{"type":224,"tag":260,"props":2142,"children":2144},{"className":2143},[],[2145],{"type":229,"value":899},{"type":229,"value":2147},". That way, if the authentication method changes someday, ",{"type":224,"tag":260,"props":2149,"children":2151},{"className":2150},[],[2152],{"type":229,"value":899},{"type":229,"value":2154}," implementation won't change. Moreover, we won't mess with the same ",{"type":224,"tag":260,"props":2156,"children":2158},{"className":2157},[],[2159],{"type":229,"value":1001},{"type":229,"value":2161}," for authentication and other calls.",{"type":224,"tag":338,"props":2163,"children":2165},{"className":340,"code":2164,"language":342,"meta":207,"style":207},"public class UserApiAuthenticationService : IUserApiAuthenticationService\n{\n    private readonly IMemoryCache _memoryCache;\n    private readonly HttpClient _httpClient;\n\n    public UserApiAuthenticationService(HttpClient httpClient, IMemoryCache memoryCache)\n    {\n        _httpClient = httpClient;\n        _memoryCache = memoryCache;\n    }\n\n    public async Task\u003Cstring> RetrieveToken()\n    {\n        DateTime expirationDate;\n        if (!_memoryCache.TryGetValue(\"Token\", out string token))\n        {\n            var body = new { login = \"login\", password = \"password\" };\n            var response = await _httpClient.PostAsync(\"login\", new StringContent(JsonConvert.SerializeObject(body)));\n            (token,  expirationDate) = await response.Content.ReadAsAsync\u003CAuthResponse>();\n            _memoryCache.Set(\"Token\", token, new DateTimeOffset(expirationDate));\n        }\n        return token;\n    }\n}\n",[2166],{"type":224,"tag":260,"props":2167,"children":2168},{"__ignoreMap":207},[2169,2194,2201,2226,2249,2256,2296,2303,2322,2342,2349,2356,2391,2398,2415,2480,2488,2560,2647,2714,2781,2789,2804,2811],{"type":224,"tag":348,"props":2170,"children":2171},{"class":350,"line":351},[2172,2176,2180,2185,2189],{"type":224,"tag":348,"props":2173,"children":2174},{"style":355},[2175],{"type":229,"value":358},{"type":224,"tag":348,"props":2177,"children":2178},{"style":361},[2179],{"type":229,"value":763},{"type":224,"tag":348,"props":2181,"children":2182},{"style":361},[2183],{"type":229,"value":2184}," UserApiAuthenticationService",{"type":224,"tag":348,"props":2186,"children":2187},{"style":376},[2188],{"type":229,"value":942},{"type":224,"tag":348,"props":2190,"children":2191},{"style":361},[2192],{"type":229,"value":2193}," IUserApiAuthenticationService\n",{"type":224,"tag":348,"props":2195,"children":2196},{"class":350,"line":372},[2197],{"type":224,"tag":348,"props":2198,"children":2199},{"style":376},[2200],{"type":229,"value":379},{"type":224,"tag":348,"props":2202,"children":2203},{"class":350,"line":382},[2204,2208,2212,2217,2222],{"type":224,"tag":348,"props":2205,"children":2206},{"style":355},[2207],{"type":229,"value":961},{"type":224,"tag":348,"props":2209,"children":2210},{"style":355},[2211],{"type":229,"value":966},{"type":224,"tag":348,"props":2213,"children":2214},{"style":361},[2215],{"type":229,"value":2216}," IMemoryCache",{"type":224,"tag":348,"props":2218,"children":2219},{"style":361},[2220],{"type":229,"value":2221}," _memoryCache",{"type":224,"tag":348,"props":2223,"children":2224},{"style":376},[2225],{"type":229,"value":980},{"type":224,"tag":348,"props":2227,"children":2228},{"class":350,"line":426},[2229,2233,2237,2241,2245],{"type":224,"tag":348,"props":2230,"children":2231},{"style":355},[2232],{"type":229,"value":961},{"type":224,"tag":348,"props":2234,"children":2235},{"style":355},[2236],{"type":229,"value":966},{"type":224,"tag":348,"props":2238,"children":2239},{"style":361},[2240],{"type":229,"value":971},{"type":224,"tag":348,"props":2242,"children":2243},{"style":361},[2244],{"type":229,"value":601},{"type":224,"tag":348,"props":2246,"children":2247},{"style":376},[2248],{"type":229,"value":980},{"type":224,"tag":348,"props":2250,"children":2251},{"class":350,"line":458},[2252],{"type":224,"tag":348,"props":2253,"children":2254},{"emptyLinePlaceholder":1056},[2255],{"type":229,"value":1059},{"type":224,"tag":348,"props":2257,"children":2258},{"class":350,"line":1022},[2259,2263,2267,2271,2275,2279,2283,2287,2292],{"type":224,"tag":348,"props":2260,"children":2261},{"style":355},[2262],{"type":229,"value":988},{"type":224,"tag":348,"props":2264,"children":2265},{"style":415},[2266],{"type":229,"value":2184},{"type":224,"tag":348,"props":2268,"children":2269},{"style":376},[2270],{"type":229,"value":441},{"type":224,"tag":348,"props":2272,"children":2273},{"style":361},[2274],{"type":229,"value":1001},{"type":224,"tag":348,"props":2276,"children":2277},{"style":361},[2278],{"type":229,"value":1006},{"type":224,"tag":348,"props":2280,"children":2281},{"style":376},[2282],{"type":229,"value":548},{"type":224,"tag":348,"props":2284,"children":2285},{"style":361},[2286],{"type":229,"value":2216},{"type":224,"tag":348,"props":2288,"children":2289},{"style":361},[2290],{"type":229,"value":2291}," memoryCache",{"type":224,"tag":348,"props":2293,"children":2294},{"style":376},[2295],{"type":229,"value":1011},{"type":224,"tag":348,"props":2297,"children":2298},{"class":350,"line":1043},[2299],{"type":224,"tag":348,"props":2300,"children":2301},{"style":376},[2302],{"type":229,"value":1019},{"type":224,"tag":348,"props":2304,"children":2305},{"class":350,"line":1052},[2306,2310,2314,2318],{"type":224,"tag":348,"props":2307,"children":2308},{"style":519},[2309],{"type":229,"value":1028},{"type":224,"tag":348,"props":2311,"children":2312},{"style":376},[2313],{"type":229,"value":527},{"type":224,"tag":348,"props":2315,"children":2316},{"style":519},[2317],{"type":229,"value":1006},{"type":224,"tag":348,"props":2319,"children":2320},{"style":376},[2321],{"type":229,"value":980},{"type":224,"tag":348,"props":2323,"children":2324},{"class":350,"line":1062},[2325,2330,2334,2338],{"type":224,"tag":348,"props":2326,"children":2327},{"style":519},[2328],{"type":229,"value":2329},"        _memoryCache ",{"type":224,"tag":348,"props":2331,"children":2332},{"style":376},[2333],{"type":229,"value":527},{"type":224,"tag":348,"props":2335,"children":2336},{"style":519},[2337],{"type":229,"value":2291},{"type":224,"tag":348,"props":2339,"children":2340},{"style":376},[2341],{"type":229,"value":980},{"type":224,"tag":348,"props":2343,"children":2344},{"class":350,"line":1109},[2345],{"type":224,"tag":348,"props":2346,"children":2347},{"style":376},[2348],{"type":229,"value":1049},{"type":224,"tag":348,"props":2350,"children":2351},{"class":350,"line":1117},[2352],{"type":224,"tag":348,"props":2353,"children":2354},{"emptyLinePlaceholder":1056},[2355],{"type":229,"value":1059},{"type":224,"tag":348,"props":2357,"children":2358},{"class":350,"line":1148},[2359,2363,2367,2371,2375,2379,2383,2387],{"type":224,"tag":348,"props":2360,"children":2361},{"style":355},[2362],{"type":229,"value":988},{"type":224,"tag":348,"props":2364,"children":2365},{"style":355},[2366],{"type":229,"value":1072},{"type":224,"tag":348,"props":2368,"children":2369},{"style":361},[2370],{"type":229,"value":1077},{"type":224,"tag":348,"props":2372,"children":2373},{"style":376},[2374],{"type":229,"value":393},{"type":224,"tag":348,"props":2376,"children":2377},{"style":376},[2378],{"type":229,"value":1800},{"type":224,"tag":348,"props":2380,"children":2381},{"style":376},[2382],{"type":229,"value":1805},{"type":224,"tag":348,"props":2384,"children":2385},{"style":415},[2386],{"type":229,"value":1141},{"type":224,"tag":348,"props":2388,"children":2389},{"style":376},[2390],{"type":229,"value":1106},{"type":224,"tag":348,"props":2392,"children":2393},{"class":350,"line":1213},[2394],{"type":224,"tag":348,"props":2395,"children":2396},{"style":376},[2397],{"type":229,"value":1019},{"type":224,"tag":348,"props":2399,"children":2400},{"class":350,"line":1282},[2401,2406,2411],{"type":224,"tag":348,"props":2402,"children":2403},{"style":361},[2404],{"type":229,"value":2405},"        DateTime",{"type":224,"tag":348,"props":2407,"children":2408},{"style":361},[2409],{"type":229,"value":2410}," expirationDate",{"type":224,"tag":348,"props":2412,"children":2413},{"style":376},[2414],{"type":229,"value":980},{"type":224,"tag":348,"props":2416,"children":2417},{"class":350,"line":1328},[2418,2423,2428,2433,2437,2442,2446,2450,2454,2458,2462,2467,2471,2475],{"type":224,"tag":348,"props":2419,"children":2420},{"style":1354},[2421],{"type":229,"value":2422},"        if",{"type":224,"tag":348,"props":2424,"children":2425},{"style":376},[2426],{"type":229,"value":2427}," (!",{"type":224,"tag":348,"props":2429,"children":2430},{"style":519},[2431],{"type":229,"value":2432},"_memoryCache",{"type":224,"tag":348,"props":2434,"children":2435},{"style":376},[2436],{"type":229,"value":291},{"type":224,"tag":348,"props":2438,"children":2439},{"style":415},[2440],{"type":229,"value":2441},"TryGetValue",{"type":224,"tag":348,"props":2443,"children":2444},{"style":376},[2445],{"type":229,"value":441},{"type":224,"tag":348,"props":2447,"children":2448},{"style":376},[2449],{"type":229,"value":543},{"type":224,"tag":348,"props":2451,"children":2452},{"style":535},[2453],{"type":229,"value":2054},{"type":224,"tag":348,"props":2455,"children":2456},{"style":376},[2457],{"type":229,"value":543},{"type":224,"tag":348,"props":2459,"children":2460},{"style":376},[2461],{"type":229,"value":548},{"type":224,"tag":348,"props":2463,"children":2464},{"style":355},[2465],{"type":229,"value":2466}," out",{"type":224,"tag":348,"props":2468,"children":2469},{"style":376},[2470],{"type":229,"value":788},{"type":224,"tag":348,"props":2472,"children":2473},{"style":361},[2474],{"type":229,"value":1128},{"type":224,"tag":348,"props":2476,"children":2477},{"style":376},[2478],{"type":229,"value":2479},"))\n",{"type":224,"tag":348,"props":2481,"children":2482},{"class":350,"line":1350},[2483],{"type":224,"tag":348,"props":2484,"children":2485},{"style":376},[2486],{"type":229,"value":2487},"        {\n",{"type":224,"tag":348,"props":2489,"children":2490},{"class":350,"line":1405},[2491,2496,2500,2504,2508,2512,2516,2520,2524,2528,2532,2536,2540,2544,2548,2552,2556],{"type":224,"tag":348,"props":2492,"children":2493},{"style":361},[2494],{"type":229,"value":2495},"            var",{"type":224,"tag":348,"props":2497,"children":2498},{"style":361},[2499],{"type":229,"value":501},{"type":224,"tag":348,"props":2501,"children":2502},{"style":376},[2503],{"type":229,"value":506},{"type":224,"tag":348,"props":2505,"children":2506},{"style":376},[2507],{"type":229,"value":511},{"type":224,"tag":348,"props":2509,"children":2510},{"style":376},[2511],{"type":229,"value":516},{"type":224,"tag":348,"props":2513,"children":2514},{"style":519},[2515],{"type":229,"value":522},{"type":224,"tag":348,"props":2517,"children":2518},{"style":376},[2519],{"type":229,"value":527},{"type":224,"tag":348,"props":2521,"children":2522},{"style":376},[2523],{"type":229,"value":532},{"type":224,"tag":348,"props":2525,"children":2526},{"style":535},[2527],{"type":229,"value":538},{"type":224,"tag":348,"props":2529,"children":2530},{"style":376},[2531],{"type":229,"value":543},{"type":224,"tag":348,"props":2533,"children":2534},{"style":376},[2535],{"type":229,"value":548},{"type":224,"tag":348,"props":2537,"children":2538},{"style":519},[2539],{"type":229,"value":553},{"type":224,"tag":348,"props":2541,"children":2542},{"style":376},[2543],{"type":229,"value":527},{"type":224,"tag":348,"props":2545,"children":2546},{"style":376},[2547],{"type":229,"value":532},{"type":224,"tag":348,"props":2549,"children":2550},{"style":535},[2551],{"type":229,"value":566},{"type":224,"tag":348,"props":2553,"children":2554},{"style":376},[2555],{"type":229,"value":543},{"type":224,"tag":348,"props":2557,"children":2558},{"style":376},[2559],{"type":229,"value":575},{"type":224,"tag":348,"props":2561,"children":2562},{"class":350,"line":1413},[2563,2567,2571,2575,2579,2583,2587,2591,2595,2599,2603,2607,2611,2615,2619,2623,2627,2631,2635,2639,2643],{"type":224,"tag":348,"props":2564,"children":2565},{"style":361},[2566],{"type":229,"value":2495},{"type":224,"tag":348,"props":2568,"children":2569},{"style":361},[2570],{"type":229,"value":587},{"type":224,"tag":348,"props":2572,"children":2573},{"style":376},[2574],{"type":229,"value":506},{"type":224,"tag":348,"props":2576,"children":2577},{"style":376},[2578],{"type":229,"value":596},{"type":224,"tag":348,"props":2580,"children":2581},{"style":519},[2582],{"type":229,"value":601},{"type":224,"tag":348,"props":2584,"children":2585},{"style":376},[2586],{"type":229,"value":291},{"type":224,"tag":348,"props":2588,"children":2589},{"style":415},[2590],{"type":229,"value":610},{"type":224,"tag":348,"props":2592,"children":2593},{"style":376},[2594],{"type":229,"value":441},{"type":224,"tag":348,"props":2596,"children":2597},{"style":376},[2598],{"type":229,"value":543},{"type":224,"tag":348,"props":2600,"children":2601},{"style":535},[2602],{"type":229,"value":538},{"type":224,"tag":348,"props":2604,"children":2605},{"style":376},[2606],{"type":229,"value":543},{"type":224,"tag":348,"props":2608,"children":2609},{"style":376},[2610],{"type":229,"value":548},{"type":224,"tag":348,"props":2612,"children":2613},{"style":376},[2614],{"type":229,"value":511},{"type":224,"tag":348,"props":2616,"children":2617},{"style":361},[2618],{"type":229,"value":639},{"type":224,"tag":348,"props":2620,"children":2621},{"style":376},[2622],{"type":229,"value":441},{"type":224,"tag":348,"props":2624,"children":2625},{"style":519},[2626],{"type":229,"value":648},{"type":224,"tag":348,"props":2628,"children":2629},{"style":376},[2630],{"type":229,"value":291},{"type":224,"tag":348,"props":2632,"children":2633},{"style":415},[2634],{"type":229,"value":657},{"type":224,"tag":348,"props":2636,"children":2637},{"style":376},[2638],{"type":229,"value":441},{"type":224,"tag":348,"props":2640,"children":2641},{"style":519},[2642],{"type":229,"value":666},{"type":224,"tag":348,"props":2644,"children":2645},{"style":376},[2646],{"type":229,"value":671},{"type":224,"tag":348,"props":2648,"children":2649},{"class":350,"line":1421},[2650,2655,2660,2664,2669,2674,2678,2682,2686,2690,2694,2698,2702,2706,2710],{"type":224,"tag":348,"props":2651,"children":2652},{"style":376},[2653],{"type":229,"value":2654},"            (",{"type":224,"tag":348,"props":2656,"children":2657},{"style":519},[2658],{"type":229,"value":2659},"token",{"type":224,"tag":348,"props":2661,"children":2662},{"style":376},[2663],{"type":229,"value":548},{"type":224,"tag":348,"props":2665,"children":2666},{"style":519},[2667],{"type":229,"value":2668},"  expirationDate",{"type":224,"tag":348,"props":2670,"children":2671},{"style":376},[2672],{"type":229,"value":2673},")",{"type":224,"tag":348,"props":2675,"children":2676},{"style":376},[2677],{"type":229,"value":506},{"type":224,"tag":348,"props":2679,"children":2680},{"style":376},[2681],{"type":229,"value":596},{"type":224,"tag":348,"props":2683,"children":2684},{"style":519},[2685],{"type":229,"value":587},{"type":224,"tag":348,"props":2687,"children":2688},{"style":376},[2689],{"type":229,"value":291},{"type":224,"tag":348,"props":2691,"children":2692},{"style":519},[2693],{"type":229,"value":704},{"type":224,"tag":348,"props":2695,"children":2696},{"style":376},[2697],{"type":229,"value":291},{"type":224,"tag":348,"props":2699,"children":2700},{"style":415},[2701],{"type":229,"value":713},{"type":224,"tag":348,"props":2703,"children":2704},{"style":376},[2705],{"type":229,"value":393},{"type":224,"tag":348,"props":2707,"children":2708},{"style":361},[2709],{"type":229,"value":273},{"type":224,"tag":348,"props":2711,"children":2712},{"style":376},[2713],{"type":229,"value":726},{"type":224,"tag":348,"props":2715,"children":2716},{"class":350,"line":1457},[2717,2722,2726,2731,2735,2739,2743,2747,2751,2755,2759,2763,2768,2772,2777],{"type":224,"tag":348,"props":2718,"children":2719},{"style":519},[2720],{"type":229,"value":2721},"            _memoryCache",{"type":224,"tag":348,"props":2723,"children":2724},{"style":376},[2725],{"type":229,"value":291},{"type":224,"tag":348,"props":2727,"children":2728},{"style":415},[2729],{"type":229,"value":2730},"Set",{"type":224,"tag":348,"props":2732,"children":2733},{"style":376},[2734],{"type":229,"value":441},{"type":224,"tag":348,"props":2736,"children":2737},{"style":376},[2738],{"type":229,"value":543},{"type":224,"tag":348,"props":2740,"children":2741},{"style":535},[2742],{"type":229,"value":2054},{"type":224,"tag":348,"props":2744,"children":2745},{"style":376},[2746],{"type":229,"value":543},{"type":224,"tag":348,"props":2748,"children":2749},{"style":376},[2750],{"type":229,"value":548},{"type":224,"tag":348,"props":2752,"children":2753},{"style":519},[2754],{"type":229,"value":1128},{"type":224,"tag":348,"props":2756,"children":2757},{"style":376},[2758],{"type":229,"value":548},{"type":224,"tag":348,"props":2760,"children":2761},{"style":376},[2762],{"type":229,"value":511},{"type":224,"tag":348,"props":2764,"children":2765},{"style":361},[2766],{"type":229,"value":2767}," DateTimeOffset",{"type":224,"tag":348,"props":2769,"children":2770},{"style":376},[2771],{"type":229,"value":441},{"type":224,"tag":348,"props":2773,"children":2774},{"style":519},[2775],{"type":229,"value":2776},"expirationDate",{"type":224,"tag":348,"props":2778,"children":2779},{"style":376},[2780],{"type":229,"value":1695},{"type":224,"tag":348,"props":2782,"children":2783},{"class":350,"line":1465},[2784],{"type":224,"tag":348,"props":2785,"children":2786},{"style":376},[2787],{"type":229,"value":2788},"        }\n",{"type":224,"tag":348,"props":2790,"children":2791},{"class":350,"line":1493},[2792,2796,2800],{"type":224,"tag":348,"props":2793,"children":2794},{"style":1354},[2795],{"type":229,"value":1357},{"type":224,"tag":348,"props":2797,"children":2798},{"style":519},[2799],{"type":229,"value":1128},{"type":224,"tag":348,"props":2801,"children":2802},{"style":376},[2803],{"type":229,"value":980},{"type":224,"tag":348,"props":2805,"children":2806},{"class":350,"line":1576},[2807],{"type":224,"tag":348,"props":2808,"children":2809},{"style":376},[2810],{"type":229,"value":1049},{"type":224,"tag":348,"props":2812,"children":2813},{"class":350,"line":1640},[2814],{"type":224,"tag":348,"props":2815,"children":2816},{"style":376},[2817],{"type":229,"value":464},{"type":224,"tag":225,"props":2819,"children":2820},{},[2821,2823,2829,2831,2840],{"type":229,"value":2822},"To avoid requesting always the same token to the API, we added a line to store the token in the memory cache and a line to check if the token is already in the cache before querying the API.\nWe could also have used a class as a singleton to store the token and its expiration date, but the built-in ",{"type":224,"tag":260,"props":2824,"children":2826},{"className":2825},[],[2827],{"type":229,"value":2828},"IMemoryCache",{"type":229,"value":2830}," of ASP.NET Core is more convenient and handle the expiration of the token for us by removing it from the cache when the date is passed. You can find more about cache memory in ASP.NET Core ",{"type":224,"tag":2832,"props":2833,"children":2837},"a",{"href":2834,"rel":2835},"https://docs.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-3.1",[2836],"nofollow",[2838],{"type":229,"value":2839},"here",{"type":229,"value":291},{"type":224,"tag":231,"props":2842,"children":2844},{"id":2843},"use-a-delegating-handler-to-directly-set-the-token-in-the-httpclient-request",[2845],{"type":229,"value":2846},"Use a Delegating handler to directly set the token in the HttpClient request",{"type":224,"tag":225,"props":2848,"children":2849},{},[2850,2852,2857,2859,2864,2866,2871,2873,2878,2880,2885],{"type":229,"value":2851},"Handling the token retrieval in a separate service is nice but that does not solve the issue of duplicated code. Even if the ",{"type":224,"tag":260,"props":2853,"children":2855},{"className":2854},[],[2856],{"type":229,"value":2093},{"type":229,"value":2858}," method is now part of ",{"type":224,"tag":260,"props":2860,"children":2862},{"className":2861},[],[2863],{"type":229,"value":2138},{"type":229,"value":2865},", each method of ",{"type":224,"tag":260,"props":2867,"children":2869},{"className":2868},[],[2870],{"type":229,"value":899},{"type":229,"value":2872}," will still call ",{"type":224,"tag":260,"props":2874,"children":2876},{"className":2875},[],[2877],{"type":229,"value":2093},{"type":229,"value":2879},". Moreover setting the token on each request should not be a concern of ",{"type":224,"tag":260,"props":2881,"children":2883},{"className":2882},[],[2884],{"type":229,"value":899},{"type":229,"value":291},{"type":224,"tag":225,"props":2887,"children":2888},{},[2889,2891,2897,2899,2904,2906,2910,2912,2919],{"type":229,"value":2890},"That's where come ",{"type":224,"tag":2892,"props":2893,"children":2894},"em",{},[2895],{"type":229,"value":2896},"delegating handlers",{"type":229,"value":2898},". A delegating handler is quite similar to an ASP.NET Core middleware but instead of applying some processing on an incoming request and its response, it does so on an outgoing request and its response. In concrete terms, you use a delegating handler to apply something (logging, authentication, caching ...) to HTTP requests you make to an API using an ",{"type":224,"tag":260,"props":2900,"children":2902},{"className":2901},[],[2903],{"type":229,"value":1001},{"type":229,"value":2905},". To learn more about ",{"type":224,"tag":2892,"props":2907,"children":2908},{},[2909],{"type":229,"value":2896},{"type":229,"value":2911}," there is a nice ",{"type":224,"tag":2832,"props":2913,"children":2916},{"href":2914,"rel":2915},"https://www.stevejgordon.co.uk/httpclientfactory-aspnetcore-outgoing-request-middleware-pipeline-delegatinghandlers",[2836],[2917],{"type":229,"value":2918},"article",{"type":229,"value":2920}," from Steve Gordon on the topic.",{"type":224,"tag":225,"props":2922,"children":2923},{},[2924,2926,2931],{"type":229,"value":2925},"A custom delegating handler is exactly what we need: a piece of code that all our HTTP requests from ",{"type":224,"tag":260,"props":2927,"children":2929},{"className":2928},[],[2930],{"type":229,"value":899},{"type":229,"value":2932}," will go through and where we will be able to set the token on the authentication header of each request. Here is the code of our custom delegating handler:",{"type":224,"tag":338,"props":2934,"children":2936},{"className":340,"code":2935,"language":342,"meta":207,"style":207},"public class UserApiAuthenticationHandler : DelegatingHandler\n{\n    private readonly IUserApiAuthenticationService _authenticationService;\n\n    public UserApiAuthenticationHandler(IUserApiAuthenticationService authenticationService)\n    {\n        _authenticationService = authenticationService;\n    }\n    \n    protected async override Task\u003CHttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationTokencancellationToken)\n    {\n        var token = await _authenticationService.RetrieveToken();\n        request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", token);\n        return await base.SendAsync(request, cancellationToken);\n    }\n}\n",[2937],{"type":224,"tag":260,"props":2938,"children":2939},{"__ignoreMap":207},[2940,2965,2972,2997,3004,3033,3040,3060,3067,3075,3140,3147,3182,3245,3290,3297],{"type":224,"tag":348,"props":2941,"children":2942},{"class":350,"line":351},[2943,2947,2951,2956,2960],{"type":224,"tag":348,"props":2944,"children":2945},{"style":355},[2946],{"type":229,"value":358},{"type":224,"tag":348,"props":2948,"children":2949},{"style":361},[2950],{"type":229,"value":763},{"type":224,"tag":348,"props":2952,"children":2953},{"style":361},[2954],{"type":229,"value":2955}," UserApiAuthenticationHandler",{"type":224,"tag":348,"props":2957,"children":2958},{"style":376},[2959],{"type":229,"value":942},{"type":224,"tag":348,"props":2961,"children":2962},{"style":361},[2963],{"type":229,"value":2964}," DelegatingHandler\n",{"type":224,"tag":348,"props":2966,"children":2967},{"class":350,"line":372},[2968],{"type":224,"tag":348,"props":2969,"children":2970},{"style":376},[2971],{"type":229,"value":379},{"type":224,"tag":348,"props":2973,"children":2974},{"class":350,"line":382},[2975,2979,2983,2988,2993],{"type":224,"tag":348,"props":2976,"children":2977},{"style":355},[2978],{"type":229,"value":961},{"type":224,"tag":348,"props":2980,"children":2981},{"style":355},[2982],{"type":229,"value":966},{"type":224,"tag":348,"props":2984,"children":2985},{"style":361},[2986],{"type":229,"value":2987}," IUserApiAuthenticationService",{"type":224,"tag":348,"props":2989,"children":2990},{"style":361},[2991],{"type":229,"value":2992}," _authenticationService",{"type":224,"tag":348,"props":2994,"children":2995},{"style":376},[2996],{"type":229,"value":980},{"type":224,"tag":348,"props":2998,"children":2999},{"class":350,"line":426},[3000],{"type":224,"tag":348,"props":3001,"children":3002},{"emptyLinePlaceholder":1056},[3003],{"type":229,"value":1059},{"type":224,"tag":348,"props":3005,"children":3006},{"class":350,"line":458},[3007,3011,3015,3019,3024,3029],{"type":224,"tag":348,"props":3008,"children":3009},{"style":355},[3010],{"type":229,"value":988},{"type":224,"tag":348,"props":3012,"children":3013},{"style":415},[3014],{"type":229,"value":2955},{"type":224,"tag":348,"props":3016,"children":3017},{"style":376},[3018],{"type":229,"value":441},{"type":224,"tag":348,"props":3020,"children":3021},{"style":361},[3022],{"type":229,"value":3023},"IUserApiAuthenticationService",{"type":224,"tag":348,"props":3025,"children":3026},{"style":361},[3027],{"type":229,"value":3028}," authenticationService",{"type":224,"tag":348,"props":3030,"children":3031},{"style":376},[3032],{"type":229,"value":1011},{"type":224,"tag":348,"props":3034,"children":3035},{"class":350,"line":1022},[3036],{"type":224,"tag":348,"props":3037,"children":3038},{"style":376},[3039],{"type":229,"value":1019},{"type":224,"tag":348,"props":3041,"children":3042},{"class":350,"line":1043},[3043,3048,3052,3056],{"type":224,"tag":348,"props":3044,"children":3045},{"style":519},[3046],{"type":229,"value":3047},"        _authenticationService ",{"type":224,"tag":348,"props":3049,"children":3050},{"style":376},[3051],{"type":229,"value":527},{"type":224,"tag":348,"props":3053,"children":3054},{"style":519},[3055],{"type":229,"value":3028},{"type":224,"tag":348,"props":3057,"children":3058},{"style":376},[3059],{"type":229,"value":980},{"type":224,"tag":348,"props":3061,"children":3062},{"class":350,"line":1052},[3063],{"type":224,"tag":348,"props":3064,"children":3065},{"style":376},[3066],{"type":229,"value":1049},{"type":224,"tag":348,"props":3068,"children":3069},{"class":350,"line":1062},[3070],{"type":224,"tag":348,"props":3071,"children":3072},{"style":519},[3073],{"type":229,"value":3074},"    \n",{"type":224,"tag":348,"props":3076,"children":3077},{"class":350,"line":1109},[3078,3083,3087,3092,3096,3100,3105,3109,3114,3118,3123,3127,3131,3136],{"type":224,"tag":348,"props":3079,"children":3080},{"style":355},[3081],{"type":229,"value":3082},"    protected",{"type":224,"tag":348,"props":3084,"children":3085},{"style":355},[3086],{"type":229,"value":1072},{"type":224,"tag":348,"props":3088,"children":3089},{"style":355},[3090],{"type":229,"value":3091}," override",{"type":224,"tag":348,"props":3093,"children":3094},{"style":361},[3095],{"type":229,"value":1077},{"type":224,"tag":348,"props":3097,"children":3098},{"style":376},[3099],{"type":229,"value":393},{"type":224,"tag":348,"props":3101,"children":3102},{"style":361},[3103],{"type":229,"value":3104},"HttpResponseMessage",{"type":224,"tag":348,"props":3106,"children":3107},{"style":376},[3108],{"type":229,"value":1805},{"type":224,"tag":348,"props":3110,"children":3111},{"style":415},[3112],{"type":229,"value":3113}," SendAsync",{"type":224,"tag":348,"props":3115,"children":3116},{"style":376},[3117],{"type":229,"value":441},{"type":224,"tag":348,"props":3119,"children":3120},{"style":361},[3121],{"type":229,"value":3122},"HttpRequestMessage",{"type":224,"tag":348,"props":3124,"children":3125},{"style":361},[3126],{"type":229,"value":1158},{"type":224,"tag":348,"props":3128,"children":3129},{"style":376},[3130],{"type":229,"value":548},{"type":224,"tag":348,"props":3132,"children":3133},{"style":519},[3134],{"type":229,"value":3135}," CancellationTokencancellationToken",{"type":224,"tag":348,"props":3137,"children":3138},{"style":376},[3139],{"type":229,"value":1011},{"type":224,"tag":348,"props":3141,"children":3142},{"class":350,"line":1117},[3143],{"type":224,"tag":348,"props":3144,"children":3145},{"style":376},[3146],{"type":229,"value":1019},{"type":224,"tag":348,"props":3148,"children":3149},{"class":350,"line":1148},[3150,3154,3158,3162,3166,3170,3174,3178],{"type":224,"tag":348,"props":3151,"children":3152},{"style":361},[3153],{"type":229,"value":1123},{"type":224,"tag":348,"props":3155,"children":3156},{"style":361},[3157],{"type":229,"value":1128},{"type":224,"tag":348,"props":3159,"children":3160},{"style":376},[3161],{"type":229,"value":506},{"type":224,"tag":348,"props":3163,"children":3164},{"style":376},[3165],{"type":229,"value":596},{"type":224,"tag":348,"props":3167,"children":3168},{"style":519},[3169],{"type":229,"value":2992},{"type":224,"tag":348,"props":3171,"children":3172},{"style":376},[3173],{"type":229,"value":291},{"type":224,"tag":348,"props":3175,"children":3176},{"style":415},[3177],{"type":229,"value":2093},{"type":224,"tag":348,"props":3179,"children":3180},{"style":376},[3181],{"type":229,"value":423},{"type":224,"tag":348,"props":3183,"children":3184},{"class":350,"line":1213},[3185,3189,3193,3197,3201,3205,3209,3213,3217,3221,3225,3229,3233,3237,3241],{"type":224,"tag":348,"props":3186,"children":3187},{"style":519},[3188],{"type":229,"value":1219},{"type":224,"tag":348,"props":3190,"children":3191},{"style":376},[3192],{"type":229,"value":291},{"type":224,"tag":348,"props":3194,"children":3195},{"style":519},[3196],{"type":229,"value":1228},{"type":224,"tag":348,"props":3198,"children":3199},{"style":376},[3200],{"type":229,"value":291},{"type":224,"tag":348,"props":3202,"children":3203},{"style":519},[3204],{"type":229,"value":1237},{"type":224,"tag":348,"props":3206,"children":3207},{"style":376},[3208],{"type":229,"value":527},{"type":224,"tag":348,"props":3210,"children":3211},{"style":376},[3212],{"type":229,"value":511},{"type":224,"tag":348,"props":3214,"children":3215},{"style":361},[3216],{"type":229,"value":1250},{"type":224,"tag":348,"props":3218,"children":3219},{"style":376},[3220],{"type":229,"value":441},{"type":224,"tag":348,"props":3222,"children":3223},{"style":376},[3224],{"type":229,"value":543},{"type":224,"tag":348,"props":3226,"children":3227},{"style":535},[3228],{"type":229,"value":1263},{"type":224,"tag":348,"props":3230,"children":3231},{"style":376},[3232],{"type":229,"value":543},{"type":224,"tag":348,"props":3234,"children":3235},{"style":376},[3236],{"type":229,"value":548},{"type":224,"tag":348,"props":3238,"children":3239},{"style":519},[3240],{"type":229,"value":1128},{"type":224,"tag":348,"props":3242,"children":3243},{"style":376},[3244],{"type":229,"value":455},{"type":224,"tag":348,"props":3246,"children":3247},{"class":350,"line":1282},[3248,3252,3256,3261,3265,3269,3273,3277,3281,3286],{"type":224,"tag":348,"props":3249,"children":3250},{"style":1354},[3251],{"type":229,"value":1357},{"type":224,"tag":348,"props":3253,"children":3254},{"style":376},[3255],{"type":229,"value":596},{"type":224,"tag":348,"props":3257,"children":3258},{"style":519},[3259],{"type":229,"value":3260}," base",{"type":224,"tag":348,"props":3262,"children":3263},{"style":376},[3264],{"type":229,"value":291},{"type":224,"tag":348,"props":3266,"children":3267},{"style":415},[3268],{"type":229,"value":1312},{"type":224,"tag":348,"props":3270,"children":3271},{"style":376},[3272],{"type":229,"value":441},{"type":224,"tag":348,"props":3274,"children":3275},{"style":519},[3276],{"type":229,"value":1321},{"type":224,"tag":348,"props":3278,"children":3279},{"style":376},[3280],{"type":229,"value":548},{"type":224,"tag":348,"props":3282,"children":3283},{"style":519},[3284],{"type":229,"value":3285}," cancellationToken",{"type":224,"tag":348,"props":3287,"children":3288},{"style":376},[3289],{"type":229,"value":455},{"type":224,"tag":348,"props":3291,"children":3292},{"class":350,"line":1328},[3293],{"type":224,"tag":348,"props":3294,"children":3295},{"style":376},[3296],{"type":229,"value":1049},{"type":224,"tag":348,"props":3298,"children":3299},{"class":350,"line":1350},[3300],{"type":224,"tag":348,"props":3301,"children":3302},{"style":376},[3303],{"type":229,"value":464},{"type":224,"tag":225,"props":3305,"children":3306},{},[3307],{"type":229,"value":3308},"That's it, we don't need anymore to handle token retrieval on UserService which becomes simpler:",{"type":224,"tag":338,"props":3310,"children":3312},{"className":340,"code":3311,"language":342,"meta":207,"style":207},"public class UserService : \n{\n    private readonly HttpClient _httpClient;\n    public UserService(HttpClient httpClient)\n    {\n        _httpClient = httpClient;\n    }\n\n    public async Task\u003CIReadOnlyCollection\u003CUser>> GetAllUsers()\n    {\n        var response = await _httpClient.GetAsync(new Uri(\"user\"));\n        response.EnsureSuccessStatusCode();\n        return await response.Content.ReadAsAsync\u003CIReadOnlyCollection\u003CUser>>();\n    }\n\n    public async Task UpdateUser(User userToUpdate)\n    {\n        var content = new StringContent(JsonConvert.SerializeObject(userToUpdate));\n        var response = await _httpClient.PutAsync($\"user/{userToUpdate.Name}\", content);\n        response.EnsureSuccessStatusCode();\n    }\n}\n",[3313],{"type":224,"tag":260,"props":3314,"children":3315},{"__ignoreMap":207},[3316,3340,3347,3370,3397,3404,3423,3430,3437,3480,3487,3549,3568,3619,3626,3633,3668,3675,3727,3804,3823,3830],{"type":224,"tag":348,"props":3317,"children":3318},{"class":350,"line":351},[3319,3323,3327,3331,3335],{"type":224,"tag":348,"props":3320,"children":3321},{"style":355},[3322],{"type":229,"value":358},{"type":224,"tag":348,"props":3324,"children":3325},{"style":361},[3326],{"type":229,"value":763},{"type":224,"tag":348,"props":3328,"children":3329},{"style":361},[3330],{"type":229,"value":937},{"type":224,"tag":348,"props":3332,"children":3333},{"style":376},[3334],{"type":229,"value":942},{"type":224,"tag":348,"props":3336,"children":3337},{"style":519},[3338],{"type":229,"value":3339}," \n",{"type":224,"tag":348,"props":3341,"children":3342},{"class":350,"line":372},[3343],{"type":224,"tag":348,"props":3344,"children":3345},{"style":376},[3346],{"type":229,"value":379},{"type":224,"tag":348,"props":3348,"children":3349},{"class":350,"line":382},[3350,3354,3358,3362,3366],{"type":224,"tag":348,"props":3351,"children":3352},{"style":355},[3353],{"type":229,"value":961},{"type":224,"tag":348,"props":3355,"children":3356},{"style":355},[3357],{"type":229,"value":966},{"type":224,"tag":348,"props":3359,"children":3360},{"style":361},[3361],{"type":229,"value":971},{"type":224,"tag":348,"props":3363,"children":3364},{"style":361},[3365],{"type":229,"value":601},{"type":224,"tag":348,"props":3367,"children":3368},{"style":376},[3369],{"type":229,"value":980},{"type":224,"tag":348,"props":3371,"children":3372},{"class":350,"line":426},[3373,3377,3381,3385,3389,3393],{"type":224,"tag":348,"props":3374,"children":3375},{"style":355},[3376],{"type":229,"value":988},{"type":224,"tag":348,"props":3378,"children":3379},{"style":415},[3380],{"type":229,"value":937},{"type":224,"tag":348,"props":3382,"children":3383},{"style":376},[3384],{"type":229,"value":441},{"type":224,"tag":348,"props":3386,"children":3387},{"style":361},[3388],{"type":229,"value":1001},{"type":224,"tag":348,"props":3390,"children":3391},{"style":361},[3392],{"type":229,"value":1006},{"type":224,"tag":348,"props":3394,"children":3395},{"style":376},[3396],{"type":229,"value":1011},{"type":224,"tag":348,"props":3398,"children":3399},{"class":350,"line":458},[3400],{"type":224,"tag":348,"props":3401,"children":3402},{"style":376},[3403],{"type":229,"value":1019},{"type":224,"tag":348,"props":3405,"children":3406},{"class":350,"line":1022},[3407,3411,3415,3419],{"type":224,"tag":348,"props":3408,"children":3409},{"style":519},[3410],{"type":229,"value":1028},{"type":224,"tag":348,"props":3412,"children":3413},{"style":376},[3414],{"type":229,"value":527},{"type":224,"tag":348,"props":3416,"children":3417},{"style":519},[3418],{"type":229,"value":1006},{"type":224,"tag":348,"props":3420,"children":3421},{"style":376},[3422],{"type":229,"value":980},{"type":224,"tag":348,"props":3424,"children":3425},{"class":350,"line":1043},[3426],{"type":224,"tag":348,"props":3427,"children":3428},{"style":376},[3429],{"type":229,"value":1049},{"type":224,"tag":348,"props":3431,"children":3432},{"class":350,"line":1052},[3433],{"type":224,"tag":348,"props":3434,"children":3435},{"emptyLinePlaceholder":1056},[3436],{"type":229,"value":1059},{"type":224,"tag":348,"props":3438,"children":3439},{"class":350,"line":1062},[3440,3444,3448,3452,3456,3460,3464,3468,3472,3476],{"type":224,"tag":348,"props":3441,"children":3442},{"style":355},[3443],{"type":229,"value":988},{"type":224,"tag":348,"props":3445,"children":3446},{"style":355},[3447],{"type":229,"value":1072},{"type":224,"tag":348,"props":3449,"children":3450},{"style":361},[3451],{"type":229,"value":1077},{"type":224,"tag":348,"props":3453,"children":3454},{"style":376},[3455],{"type":229,"value":393},{"type":224,"tag":348,"props":3457,"children":3458},{"style":361},[3459],{"type":229,"value":398},{"type":224,"tag":348,"props":3461,"children":3462},{"style":376},[3463],{"type":229,"value":393},{"type":224,"tag":348,"props":3465,"children":3466},{"style":361},[3467],{"type":229,"value":407},{"type":224,"tag":348,"props":3469,"children":3470},{"style":376},[3471],{"type":229,"value":412},{"type":224,"tag":348,"props":3473,"children":3474},{"style":415},[3475],{"type":229,"value":418},{"type":224,"tag":348,"props":3477,"children":3478},{"style":376},[3479],{"type":229,"value":1106},{"type":224,"tag":348,"props":3481,"children":3482},{"class":350,"line":1109},[3483],{"type":224,"tag":348,"props":3484,"children":3485},{"style":376},[3486],{"type":229,"value":1019},{"type":224,"tag":348,"props":3488,"children":3489},{"class":350,"line":1117},[3490,3494,3498,3502,3506,3510,3514,3519,3524,3529,3533,3537,3541,3545],{"type":224,"tag":348,"props":3491,"children":3492},{"style":361},[3493],{"type":229,"value":1123},{"type":224,"tag":348,"props":3495,"children":3496},{"style":361},[3497],{"type":229,"value":587},{"type":224,"tag":348,"props":3499,"children":3500},{"style":376},[3501],{"type":229,"value":506},{"type":224,"tag":348,"props":3503,"children":3504},{"style":376},[3505],{"type":229,"value":596},{"type":224,"tag":348,"props":3507,"children":3508},{"style":519},[3509],{"type":229,"value":601},{"type":224,"tag":348,"props":3511,"children":3512},{"style":376},[3513],{"type":229,"value":291},{"type":224,"tag":348,"props":3515,"children":3516},{"style":415},[3517],{"type":229,"value":3518},"GetAsync",{"type":224,"tag":348,"props":3520,"children":3521},{"style":376},[3522],{"type":229,"value":3523},"(new",{"type":224,"tag":348,"props":3525,"children":3526},{"style":361},[3527],{"type":229,"value":3528}," Uri",{"type":224,"tag":348,"props":3530,"children":3531},{"style":376},[3532],{"type":229,"value":441},{"type":224,"tag":348,"props":3534,"children":3535},{"style":376},[3536],{"type":229,"value":543},{"type":224,"tag":348,"props":3538,"children":3539},{"style":535},[3540],{"type":229,"value":1202},{"type":224,"tag":348,"props":3542,"children":3543},{"style":376},[3544],{"type":229,"value":543},{"type":224,"tag":348,"props":3546,"children":3547},{"style":376},[3548],{"type":229,"value":1695},{"type":224,"tag":348,"props":3550,"children":3551},{"class":350,"line":1148},[3552,3556,3560,3564],{"type":224,"tag":348,"props":3553,"children":3554},{"style":519},[3555],{"type":229,"value":1334},{"type":224,"tag":348,"props":3557,"children":3558},{"style":376},[3559],{"type":229,"value":291},{"type":224,"tag":348,"props":3561,"children":3562},{"style":415},[3563],{"type":229,"value":1343},{"type":224,"tag":348,"props":3565,"children":3566},{"style":376},[3567],{"type":229,"value":423},{"type":224,"tag":348,"props":3569,"children":3570},{"class":350,"line":1213},[3571,3575,3579,3583,3587,3591,3595,3599,3603,3607,3611,3615],{"type":224,"tag":348,"props":3572,"children":3573},{"style":1354},[3574],{"type":229,"value":1357},{"type":224,"tag":348,"props":3576,"children":3577},{"style":376},[3578],{"type":229,"value":596},{"type":224,"tag":348,"props":3580,"children":3581},{"style":519},[3582],{"type":229,"value":587},{"type":224,"tag":348,"props":3584,"children":3585},{"style":376},[3586],{"type":229,"value":291},{"type":224,"tag":348,"props":3588,"children":3589},{"style":519},[3590],{"type":229,"value":704},{"type":224,"tag":348,"props":3592,"children":3593},{"style":376},[3594],{"type":229,"value":291},{"type":224,"tag":348,"props":3596,"children":3597},{"style":415},[3598],{"type":229,"value":713},{"type":224,"tag":348,"props":3600,"children":3601},{"style":376},[3602],{"type":229,"value":393},{"type":224,"tag":348,"props":3604,"children":3605},{"style":361},[3606],{"type":229,"value":398},{"type":224,"tag":348,"props":3608,"children":3609},{"style":376},[3610],{"type":229,"value":393},{"type":224,"tag":348,"props":3612,"children":3613},{"style":361},[3614],{"type":229,"value":407},{"type":224,"tag":348,"props":3616,"children":3617},{"style":376},[3618],{"type":229,"value":1402},{"type":224,"tag":348,"props":3620,"children":3621},{"class":350,"line":1282},[3622],{"type":224,"tag":348,"props":3623,"children":3624},{"style":376},[3625],{"type":229,"value":1049},{"type":224,"tag":348,"props":3627,"children":3628},{"class":350,"line":1328},[3629],{"type":224,"tag":348,"props":3630,"children":3631},{"emptyLinePlaceholder":1056},[3632],{"type":229,"value":1059},{"type":224,"tag":348,"props":3634,"children":3635},{"class":350,"line":1350},[3636,3640,3644,3648,3652,3656,3660,3664],{"type":224,"tag":348,"props":3637,"children":3638},{"style":355},[3639],{"type":229,"value":988},{"type":224,"tag":348,"props":3641,"children":3642},{"style":355},[3643],{"type":229,"value":1072},{"type":224,"tag":348,"props":3645,"children":3646},{"style":361},[3647],{"type":229,"value":1077},{"type":224,"tag":348,"props":3649,"children":3650},{"style":415},[3651],{"type":229,"value":436},{"type":224,"tag":348,"props":3653,"children":3654},{"style":376},[3655],{"type":229,"value":441},{"type":224,"tag":348,"props":3657,"children":3658},{"style":361},[3659],{"type":229,"value":407},{"type":224,"tag":348,"props":3661,"children":3662},{"style":361},[3663],{"type":229,"value":450},{"type":224,"tag":348,"props":3665,"children":3666},{"style":376},[3667],{"type":229,"value":1011},{"type":224,"tag":348,"props":3669,"children":3670},{"class":350,"line":1405},[3671],{"type":224,"tag":348,"props":3672,"children":3673},{"style":376},[3674],{"type":229,"value":1019},{"type":224,"tag":348,"props":3676,"children":3677},{"class":350,"line":1413},[3678,3682,3687,3691,3695,3699,3703,3707,3711,3715,3719,3723],{"type":224,"tag":348,"props":3679,"children":3680},{"style":361},[3681],{"type":229,"value":1123},{"type":224,"tag":348,"props":3683,"children":3684},{"style":361},[3685],{"type":229,"value":3686}," content",{"type":224,"tag":348,"props":3688,"children":3689},{"style":376},[3690],{"type":229,"value":506},{"type":224,"tag":348,"props":3692,"children":3693},{"style":376},[3694],{"type":229,"value":511},{"type":224,"tag":348,"props":3696,"children":3697},{"style":361},[3698],{"type":229,"value":639},{"type":224,"tag":348,"props":3700,"children":3701},{"style":376},[3702],{"type":229,"value":441},{"type":224,"tag":348,"props":3704,"children":3705},{"style":519},[3706],{"type":229,"value":648},{"type":224,"tag":348,"props":3708,"children":3709},{"style":376},[3710],{"type":229,"value":291},{"type":224,"tag":348,"props":3712,"children":3713},{"style":415},[3714],{"type":229,"value":657},{"type":224,"tag":348,"props":3716,"children":3717},{"style":376},[3718],{"type":229,"value":441},{"type":224,"tag":348,"props":3720,"children":3721},{"style":519},[3722],{"type":229,"value":1555},{"type":224,"tag":348,"props":3724,"children":3725},{"style":376},[3726],{"type":229,"value":1695},{"type":224,"tag":348,"props":3728,"children":3729},{"class":350,"line":1421},[3730,3734,3738,3742,3746,3750,3754,3759,3763,3768,3772,3776,3780,3784,3788,3792,3796,3800],{"type":224,"tag":348,"props":3731,"children":3732},{"style":361},[3733],{"type":229,"value":1123},{"type":224,"tag":348,"props":3735,"children":3736},{"style":361},[3737],{"type":229,"value":587},{"type":224,"tag":348,"props":3739,"children":3740},{"style":376},[3741],{"type":229,"value":506},{"type":224,"tag":348,"props":3743,"children":3744},{"style":376},[3745],{"type":229,"value":596},{"type":224,"tag":348,"props":3747,"children":3748},{"style":519},[3749],{"type":229,"value":601},{"type":224,"tag":348,"props":3751,"children":3752},{"style":376},[3753],{"type":229,"value":291},{"type":224,"tag":348,"props":3755,"children":3756},{"style":415},[3757],{"type":229,"value":3758},"PutAsync",{"type":224,"tag":348,"props":3760,"children":3761},{"style":376},[3762],{"type":229,"value":441},{"type":224,"tag":348,"props":3764,"children":3765},{"style":376},[3766],{"type":229,"value":3767},"$\"",{"type":224,"tag":348,"props":3769,"children":3770},{"style":535},[3771],{"type":229,"value":1545},{"type":224,"tag":348,"props":3773,"children":3774},{"style":376},[3775],{"type":229,"value":1550},{"type":224,"tag":348,"props":3777,"children":3778},{"style":519},[3779],{"type":229,"value":1555},{"type":224,"tag":348,"props":3781,"children":3782},{"style":376},[3783],{"type":229,"value":291},{"type":224,"tag":348,"props":3785,"children":3786},{"style":519},[3787],{"type":229,"value":1564},{"type":224,"tag":348,"props":3789,"children":3790},{"style":376},[3791],{"type":229,"value":1569},{"type":224,"tag":348,"props":3793,"children":3794},{"style":376},[3795],{"type":229,"value":548},{"type":224,"tag":348,"props":3797,"children":3798},{"style":519},[3799],{"type":229,"value":3686},{"type":224,"tag":348,"props":3801,"children":3802},{"style":376},[3803],{"type":229,"value":455},{"type":224,"tag":348,"props":3805,"children":3806},{"class":350,"line":1457},[3807,3811,3815,3819],{"type":224,"tag":348,"props":3808,"children":3809},{"style":519},[3810],{"type":229,"value":1334},{"type":224,"tag":348,"props":3812,"children":3813},{"style":376},[3814],{"type":229,"value":291},{"type":224,"tag":348,"props":3816,"children":3817},{"style":415},[3818],{"type":229,"value":1343},{"type":224,"tag":348,"props":3820,"children":3821},{"style":376},[3822],{"type":229,"value":423},{"type":224,"tag":348,"props":3824,"children":3825},{"class":350,"line":1465},[3826],{"type":224,"tag":348,"props":3827,"children":3828},{"style":376},[3829],{"type":229,"value":1049},{"type":224,"tag":348,"props":3831,"children":3832},{"class":350,"line":1493},[3833],{"type":224,"tag":348,"props":3834,"children":3835},{"style":376},[3836],{"type":229,"value":464},{"type":224,"tag":225,"props":3838,"children":3839},{},[3840,3842,3848],{"type":229,"value":3841},"To finish we just have to specify in the ",{"type":224,"tag":260,"props":3843,"children":3845},{"className":3844},[],[3846],{"type":229,"value":3847},"Startup.cs",{"type":229,"value":3849}," on which HttpClient to apply the delegating handler we have just created.",{"type":224,"tag":338,"props":3851,"children":3853},{"className":340,"code":3852,"language":342,"meta":207,"style":207},"public void ConfigureServices(IServiceCollectionservices)\n{\n    services.AddMemoryCache();\n    services.AddHttpClient\u003CIUserApiAuthenticationService, UserApiAuthenticationService>()\n            .ConfigureHttpClient(c => c.BaseAddress =\"http://urltotheuserapi.com\");\n    \n    services.AddTransient\u003CUserApiAuthenticationHandler>();\n    services.AddHttpClient\u003CUserService, UserService>()\n            .ConfigureHttpClient(c => c.BaseAddress =\"http://urltotheuserapi.com\")\n            .AddHttpMessageHandler\u003CUserApiAuthenticationHanler>();\n}\n",[3854],{"type":224,"tag":260,"props":3855,"children":3856},{"__ignoreMap":207},[3857,3887,3894,3915,3952,4014,4021,4050,4085,4140,4165],{"type":224,"tag":348,"props":3858,"children":3859},{"class":350,"line":351},[3860,3864,3869,3874,3878,3883],{"type":224,"tag":348,"props":3861,"children":3862},{"style":355},[3863],{"type":229,"value":358},{"type":224,"tag":348,"props":3865,"children":3866},{"style":376},[3867],{"type":229,"value":3868}," void",{"type":224,"tag":348,"props":3870,"children":3871},{"style":415},[3872],{"type":229,"value":3873}," ConfigureServices",{"type":224,"tag":348,"props":3875,"children":3876},{"style":376},[3877],{"type":229,"value":441},{"type":224,"tag":348,"props":3879,"children":3880},{"style":519},[3881],{"type":229,"value":3882},"IServiceCollectionservices",{"type":224,"tag":348,"props":3884,"children":3885},{"style":376},[3886],{"type":229,"value":1011},{"type":224,"tag":348,"props":3888,"children":3889},{"class":350,"line":372},[3890],{"type":224,"tag":348,"props":3891,"children":3892},{"style":376},[3893],{"type":229,"value":379},{"type":224,"tag":348,"props":3895,"children":3896},{"class":350,"line":382},[3897,3902,3906,3911],{"type":224,"tag":348,"props":3898,"children":3899},{"style":519},[3900],{"type":229,"value":3901},"    services",{"type":224,"tag":348,"props":3903,"children":3904},{"style":376},[3905],{"type":229,"value":291},{"type":224,"tag":348,"props":3907,"children":3908},{"style":415},[3909],{"type":229,"value":3910},"AddMemoryCache",{"type":224,"tag":348,"props":3912,"children":3913},{"style":376},[3914],{"type":229,"value":423},{"type":224,"tag":348,"props":3916,"children":3917},{"class":350,"line":426},[3918,3922,3926,3931,3935,3939,3943,3947],{"type":224,"tag":348,"props":3919,"children":3920},{"style":519},[3921],{"type":229,"value":3901},{"type":224,"tag":348,"props":3923,"children":3924},{"style":376},[3925],{"type":229,"value":291},{"type":224,"tag":348,"props":3927,"children":3928},{"style":415},[3929],{"type":229,"value":3930},"AddHttpClient",{"type":224,"tag":348,"props":3932,"children":3933},{"style":376},[3934],{"type":229,"value":393},{"type":224,"tag":348,"props":3936,"children":3937},{"style":361},[3938],{"type":229,"value":3023},{"type":224,"tag":348,"props":3940,"children":3941},{"style":376},[3942],{"type":229,"value":548},{"type":224,"tag":348,"props":3944,"children":3945},{"style":361},[3946],{"type":229,"value":2184},{"type":224,"tag":348,"props":3948,"children":3949},{"style":376},[3950],{"type":229,"value":3951},">()\n",{"type":224,"tag":348,"props":3953,"children":3954},{"class":350,"line":458},[3955,3960,3965,3969,3974,3979,3984,3988,3993,3997,4001,4006,4010],{"type":224,"tag":348,"props":3956,"children":3957},{"style":376},[3958],{"type":229,"value":3959},"            .",{"type":224,"tag":348,"props":3961,"children":3962},{"style":415},[3963],{"type":229,"value":3964},"ConfigureHttpClient",{"type":224,"tag":348,"props":3966,"children":3967},{"style":376},[3968],{"type":229,"value":441},{"type":224,"tag":348,"props":3970,"children":3971},{"style":361},[3972],{"type":229,"value":3973},"c",{"type":224,"tag":348,"props":3975,"children":3976},{"style":376},[3977],{"type":229,"value":3978}," =>",{"type":224,"tag":348,"props":3980,"children":3981},{"style":519},[3982],{"type":229,"value":3983}," c",{"type":224,"tag":348,"props":3985,"children":3986},{"style":376},[3987],{"type":229,"value":291},{"type":224,"tag":348,"props":3989,"children":3990},{"style":519},[3991],{"type":229,"value":3992},"BaseAddress ",{"type":224,"tag":348,"props":3994,"children":3995},{"style":376},[3996],{"type":229,"value":527},{"type":224,"tag":348,"props":3998,"children":3999},{"style":376},[4000],{"type":229,"value":543},{"type":224,"tag":348,"props":4002,"children":4003},{"style":535},[4004],{"type":229,"value":4005},"http://urltotheuserapi.com",{"type":224,"tag":348,"props":4007,"children":4008},{"style":376},[4009],{"type":229,"value":543},{"type":224,"tag":348,"props":4011,"children":4012},{"style":376},[4013],{"type":229,"value":455},{"type":224,"tag":348,"props":4015,"children":4016},{"class":350,"line":1022},[4017],{"type":224,"tag":348,"props":4018,"children":4019},{"style":519},[4020],{"type":229,"value":3074},{"type":224,"tag":348,"props":4022,"children":4023},{"class":350,"line":1043},[4024,4028,4032,4037,4041,4046],{"type":224,"tag":348,"props":4025,"children":4026},{"style":519},[4027],{"type":229,"value":3901},{"type":224,"tag":348,"props":4029,"children":4030},{"style":376},[4031],{"type":229,"value":291},{"type":224,"tag":348,"props":4033,"children":4034},{"style":415},[4035],{"type":229,"value":4036},"AddTransient",{"type":224,"tag":348,"props":4038,"children":4039},{"style":376},[4040],{"type":229,"value":393},{"type":224,"tag":348,"props":4042,"children":4043},{"style":361},[4044],{"type":229,"value":4045},"UserApiAuthenticationHandler",{"type":224,"tag":348,"props":4047,"children":4048},{"style":376},[4049],{"type":229,"value":726},{"type":224,"tag":348,"props":4051,"children":4052},{"class":350,"line":1052},[4053,4057,4061,4065,4069,4073,4077,4081],{"type":224,"tag":348,"props":4054,"children":4055},{"style":519},[4056],{"type":229,"value":3901},{"type":224,"tag":348,"props":4058,"children":4059},{"style":376},[4060],{"type":229,"value":291},{"type":224,"tag":348,"props":4062,"children":4063},{"style":415},[4064],{"type":229,"value":3930},{"type":224,"tag":348,"props":4066,"children":4067},{"style":376},[4068],{"type":229,"value":393},{"type":224,"tag":348,"props":4070,"children":4071},{"style":361},[4072],{"type":229,"value":899},{"type":224,"tag":348,"props":4074,"children":4075},{"style":376},[4076],{"type":229,"value":548},{"type":224,"tag":348,"props":4078,"children":4079},{"style":361},[4080],{"type":229,"value":937},{"type":224,"tag":348,"props":4082,"children":4083},{"style":376},[4084],{"type":229,"value":3951},{"type":224,"tag":348,"props":4086,"children":4087},{"class":350,"line":1062},[4088,4092,4096,4100,4104,4108,4112,4116,4120,4124,4128,4132,4136],{"type":224,"tag":348,"props":4089,"children":4090},{"style":376},[4091],{"type":229,"value":3959},{"type":224,"tag":348,"props":4093,"children":4094},{"style":415},[4095],{"type":229,"value":3964},{"type":224,"tag":348,"props":4097,"children":4098},{"style":376},[4099],{"type":229,"value":441},{"type":224,"tag":348,"props":4101,"children":4102},{"style":361},[4103],{"type":229,"value":3973},{"type":224,"tag":348,"props":4105,"children":4106},{"style":376},[4107],{"type":229,"value":3978},{"type":224,"tag":348,"props":4109,"children":4110},{"style":519},[4111],{"type":229,"value":3983},{"type":224,"tag":348,"props":4113,"children":4114},{"style":376},[4115],{"type":229,"value":291},{"type":224,"tag":348,"props":4117,"children":4118},{"style":519},[4119],{"type":229,"value":3992},{"type":224,"tag":348,"props":4121,"children":4122},{"style":376},[4123],{"type":229,"value":527},{"type":224,"tag":348,"props":4125,"children":4126},{"style":376},[4127],{"type":229,"value":543},{"type":224,"tag":348,"props":4129,"children":4130},{"style":535},[4131],{"type":229,"value":4005},{"type":224,"tag":348,"props":4133,"children":4134},{"style":376},[4135],{"type":229,"value":543},{"type":224,"tag":348,"props":4137,"children":4138},{"style":376},[4139],{"type":229,"value":1011},{"type":224,"tag":348,"props":4141,"children":4142},{"class":350,"line":1109},[4143,4147,4152,4156,4161],{"type":224,"tag":348,"props":4144,"children":4145},{"style":376},[4146],{"type":229,"value":3959},{"type":224,"tag":348,"props":4148,"children":4149},{"style":415},[4150],{"type":229,"value":4151},"AddHttpMessageHandler",{"type":224,"tag":348,"props":4153,"children":4154},{"style":376},[4155],{"type":229,"value":393},{"type":224,"tag":348,"props":4157,"children":4158},{"style":361},[4159],{"type":229,"value":4160},"UserApiAuthenticationHanler",{"type":224,"tag":348,"props":4162,"children":4163},{"style":376},[4164],{"type":229,"value":726},{"type":224,"tag":348,"props":4166,"children":4167},{"class":350,"line":1117},[4168],{"type":224,"tag":348,"props":4169,"children":4170},{"style":376},[4171],{"type":229,"value":464},{"type":224,"tag":231,"props":4173,"children":4175},{"id":4174},"to-conclude",[4176],{"type":229,"value":4177},"To conclude",{"type":224,"tag":225,"props":4179,"children":4180},{},[4181],{"type":229,"value":4182},"To summarize, we have put the code that retrieves a token in a separate dedicated service that caches the token until it expires. And we have created a custom delegating handler that calls this service and sets the retrieved token on the authentication header of each HTTP request to the API.",{"type":224,"tag":4184,"props":4185,"children":4186},"style",{},[4187],{"type":229,"value":4188},"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":207,"searchDepth":372,"depth":372,"links":4190},[4191,4192,4193,4194,4195],{"id":233,"depth":372,"text":236},{"id":885,"depth":372,"text":888},{"id":2117,"depth":372,"text":2120},{"id":2843,"depth":372,"text":2846},{"id":4174,"depth":372,"text":4177},"markdown","content:1.posts:5.delegating-handler.md","content","1.posts/5.delegating-handler.md","md",[4202,4217],{"_path":25,"_dir":205,"_draft":206,"_partial":206,"_locale":207,"title":24,"description":4203,"lead":4204,"date":4205,"image":4206,"badge":4208,"tags":4210,"_type":4196,"_id":4215,"_source":4198,"_file":4216,"_extension":4200},"When working on a git repository, I often have to manually delete old local branches that I don't use anymore. That's not a huge waste of time but still, that's something I have to do quite often so I decided to automate that.","Playing with Nushell to create a useful git alias to delete unused local git branches.","2020-04-06T00:00:00.000Z",{"src":4207},"/images/branches_1.jpg",{"label":4209},"Tips",[4211,4212,4213,4214],"tooling","git","shell","nushell","content:1.posts:6.cleaning-git-branches.md","1.posts/6.cleaning-git-branches.md",{"_path":19,"_dir":205,"_draft":206,"_partial":206,"_locale":207,"title":18,"description":4218,"lead":4219,"date":4220,"image":4221,"tags":4223,"badge":4226,"_type":4196,"_id":4228,"_source":4198,"_file":4229,"_extension":4200},"The other day when I was looking for a way to automate my development environment setup, I came across Gitpod. Not really what I was looking for but I discovered an awesome tool for working on open source projects.","An IDE in the browser","2019-08-12T00:00:00.000Z",{"src":4222},"/images/github-usbkey.jpg",[4224,4211,4225],"GitHub","vscode",{"label":4227},"Tooling","content:1.posts:4.gitpod.md","1.posts/4.gitpod.md",1716749602479]