|
| 1 | +--- |
| 2 | +title: Enable an authentication token store in Azure Container Apps |
| 3 | +description: Learn to secure authentication tokens independent of your application. |
| 4 | +services: container-apps |
| 5 | +author: craigshoemaker |
| 6 | +ms.service: container-apps |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 04/04/2024 |
| 9 | +ms.author: cshoe |
| 10 | +--- |
| 11 | + |
| 12 | +# Enable an authentication token store in Azure Container Apps |
| 13 | + |
| 14 | +Azure Container Apps authentication supports a feature called token store. A token store is a repository of tokens that are associated with the users of your web apps and APIs. You enable a token store by configuring your container app with an Azure Blob Storage container. |
| 15 | + |
| 16 | +Your application code sometimes needs to access data from these providers on the user's behalf, such as: |
| 17 | + |
| 18 | +* Post to an authenticated user's Facebook timeline |
| 19 | +* Read a user's corporate data using the Microsoft Graph API |
| 20 | + |
| 21 | +You typically need to write code to collect, store, and refresh tokens in your application. With a token store, you can [retrieve tokens](../app-service/configure-authentication-oauth-tokens.md#retrieve-tokens-in-app-code) when you need them, and [tell Container Apps to refresh them](../app-service/configure-authentication-oauth-tokens.md#refresh-auth-tokens) as they become invalid. |
| 22 | + |
| 23 | +When token store is enabled, the Container Apps authentication system caches ID tokens, access tokens, and refresh tokens the authenticated session, and they're accessible only by the associated user. |
| 24 | + |
| 25 | +## Generate a SAS URL |
| 26 | + |
| 27 | +Before you can create a token store for your container app, you first need an Azure Storage account with a private blob container. |
| 28 | + |
| 29 | +1. Go to your storage account or [create a new one](/azure/storage/common/storage-account-create?tabs=azure-portal) in the Azure portal. |
| 30 | + |
| 31 | +1. Select **Containers** and create a private blob container if necessary. |
| 32 | + |
| 33 | +1. Select the three dots (•••) at the end of the row for the storage container where you want to create your token store. |
| 34 | + |
| 35 | +1. Enter the values appropriate for your needs in the *Generate SAS* window. |
| 36 | + |
| 37 | + Make sure you include the *read*, *write* and *delete* permissions in your definition. |
| 38 | + |
| 39 | + > [!NOTE] |
| 40 | + > Make sure you keep track of your SAS expiration dates to ensure access to your container doesn't cease. |
| 41 | +
|
| 42 | +1. Select the **Generate SAS token URL** button to generate the SAS URL. |
| 43 | + |
| 44 | +1. Copy the SAS URL and paste it into a text editor for use in a following step. |
| 45 | + |
| 46 | +## Save SAS URL as secret |
| 47 | + |
| 48 | +With SAS URL generated, you can save it in your container app as a secret. Make sure the permissions associated with your store include valid permissions to your blob storage container. |
| 49 | + |
| 50 | +1. Go to your container app in the Azure portal. |
| 51 | + |
| 52 | +1. Select **Secrets**. |
| 53 | + |
| 54 | +1. Select **Add** and enter the following values in the *Add secret* window. |
| 55 | + |
| 56 | + | Property | Value | |
| 57 | + |---|---| |
| 58 | + | Key | Enter a name for your SAS secret. | |
| 59 | + | Type | Select **Container Apps secret**. | |
| 60 | + | Value | Enter the SAS URL value you generated from your storage container. | |
| 61 | + |
| 62 | +## Create a token store |
| 63 | + |
| 64 | +Use the `containerapp auth update` command to associate your Azure Storage account to your container app and create the token store. |
| 65 | + |
| 66 | +In this example, you put your values in place of the placeholder tokens surrounded by `<>` brackets. |
| 67 | + |
| 68 | +```azurecli |
| 69 | +az containerapp auth update \ |
| 70 | + --resource-group <RESOURCE_GROUP_NAME> \ |
| 71 | + --name <CONTAINER_APP_NAME> \ |
| 72 | + --sas-url-secret-name <SAS_SECRET_NAME> \ |
| 73 | + --token-store true |
| 74 | +``` |
| 75 | + |
| 76 | +Additionally, you can create your store using an [ARM template](/rest/api/containerapps/container-apps-auth-configs/create-or-update). |
| 77 | + |
| 78 | +## Next steps |
| 79 | + |
| 80 | +> [!div class="nextstepaction"] |
| 81 | +> [Customize sign in and sign out](authentication.md#customize-sign-in-and-sign-out) |
0 commit comments