<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y" -->

---
title: Making API calls using the access token and refresh...
description: A walkthrough shows how to retrieve and refresh OAuth access and refresh tokens stored in an ASP.NET Core authentication cookie after a user signs in via an...
canonical: https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Making API calls using the access token and refresh token from an ASP.NET Core authentication handler | daily.dev
og:description: A walkthrough shows how to retrieve and refresh OAuth access and refresh tokens stored in an ASP.NET Core authentication cookie after a user signs in via an...
og:url: https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y
og:image: https://api.daily.dev/og/posts/34C1W5Y8Y.png
og:image:alt: Making API calls using the access token and refresh token from an ASP.NET Core authentication handler
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Making API calls using the access token and refresh token from an ASP.NET Core authentication handler

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 4 min read · 0 upvotes · 0 comments

## Summary

A walkthrough shows how to retrieve and refresh OAuth access and refresh tokens stored in an ASP.NET Core authentication cookie after a user signs in via an OAuth-based handler (such as one built for JetBrains Space). It demonstrates using HttpContext.GetTokenAsync and HttpContext.AuthenticateAsync to read tokens, and AuthenticationProperties.UpdateTokenValue to write refreshed tokens back into the cookie, with a working example calling a Space API client. The author notes this requires too much boilerplate per API call and points to IdentityModel.AspNetCore as a project working on transparent token management.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2020-01-13-making-api-calls-using-the-access-token-and-refresh-token-from-an-aspnet-core-authentication-handler>

## Questions this post answers

### How do I get the OAuth access token from HttpContext in an ASP.NET Core authentication handler?

Call the GetTokenAsync extension method on HttpContext, passing the token name such as access_token, refresh_token, or expires_at. These values are automatically available because ASP.NET Core authentication handlers store them in the authentication cookie when SaveTokens is set to true during AddCookie/AddOAuth configuration.

_Developers wiring up OAuth token refresh flows can compare approaches like this on daily.dev._

### How can I update the access token and refresh token stored in an ASP.NET Core authentication cookie after refreshing them?

Call HttpContext.AuthenticateAsync to get the AuthenticationProperties, then use Properties.UpdateTokenValue for access_token, refresh_token, and expires_at with the newly refreshed values. This updates the values held in the authentication cookie so subsequent requests use the refreshed tokens without re-authenticating the user.

_Anyone debugging token refresh logic in cookie-based auth can find similar patterns on daily.dev._

## Similar posts on daily.dev

- [ASP.NET Core Security Explained: Modern Authentication, Authorization, and JWT](https://daily.dev/posts/asp-net-core-security-explained-modern-authentication-authorization-and-jwt-bgq4u3gn4) · Syncfusion · 4 upvotes · 0 comments
- [Using ASP.NET Core Passkeys for Second Factor Authentication](https://daily.dev/posts/using-asp-net-core-passkeys-for-second-factor-authentication-oh2mcwiop) · Maarten Balliauw · 0 upvotes · 0 comments
- [How to Secure APIs with OAuth 2.1 and OpenID Connect](https://daily.dev/posts/how-to-secure-apis-with-oauth-2-1-and-openid-connect-rf7g6orkv) · C\# Corner · 0 upvotes · 1 comments
- [Integrate Keycloak with ASP.NET Core Using OAuth 2.0](https://daily.dev/posts/integrate-keycloak-with-asp-net-core-using-oauth-2-0-w348tdawg) · Milan Jovanović · 11 upvotes · 1 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#c#](https://daily.dev/tags/c#), [#aspnet](https://daily.dev/tags/aspnet)

[View this post on daily.dev](https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Making API calls using the access token and refresh token from an ASP.NET Core authentication handler","url":"https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y"},"datePublished":"2026-10-04T13:04:27.604Z","dateModified":"2026-10-04T13:06:48.684Z","description":"A walkthrough shows how to retrieve and refresh OAuth access and refresh tokens stored in an ASP.NET Core authentication cookie after a user signs in via an...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d9573f229660f8d24f83821844922a68?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d9573f229660f8d24f83821844922a68?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,c#,aspnet","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Making API calls using the access token and refresh token from an ASP.NET Core authentication handler"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/making-api-calls-using-the-access-token-and-refresh-token-from-an-asp-net-core-authentication-handle-34c1w5y8y#faq","mainEntity":[{"@type":"Question","name":"How do I get the OAuth access token from HttpContext in an ASP.NET Core authentication handler?","acceptedAnswer":{"@type":"Answer","text":"Call the GetTokenAsync extension method on HttpContext, passing the token name such as access_token, refresh_token, or expires_at. These values are automatically available because ASP.NET Core authentication handlers store them in the authentication cookie when SaveTokens is set to true during AddCookie/AddOAuth configuration. Developers wiring up OAuth token refresh flows can compare approaches like this on daily.dev."}},{"@type":"Question","name":"How can I update the access token and refresh token stored in an ASP.NET Core authentication cookie after refreshing them?","acceptedAnswer":{"@type":"Answer","text":"Call HttpContext.AuthenticateAsync to get the AuthenticationProperties, then use Properties.UpdateTokenValue for access_token, refresh_token, and expires_at with the newly refreshed values. This updates the values held in the authentication cookie so subsequent requests use the refreshed tokens without re-authenticating the user. Anyone debugging token refresh logic in cookie-based auth can find similar patterns on daily.dev."}}]}
```

