Skip to main content Skip to complementary content

Defining custom roles for Azure Static Web Apps

Create a file in your API Portal repository to define custom roles and their access rights.

Before you begin

You have generated an API Portal repository from Talend Cloud API Designer. For more information, see Publishing an API Portal.

Procedure

  1. At the root of your API Portal repository, create a file named staticwebapp.config.json.
    This file defines routes and the user roles allowed to access them. For more information, see Routes in Azure Static Web Apps.
  2. Define your routes.
    In this example, you need to add five routes:
    • /login to allow users to log in with Azure Active Directory.
    • /logout to allow users to log out.
    • /me to display information about the user.
    • /apis/* to specify how to handle the list of APIs and the API documentation.
    • /getting-started to specify how to handle the "Getting started" page.
    • /* to specify how to handle any other page on the API Portal. This route should be the last one in the file.

    If needed, you can also use routes to block other authorization providers. For more information, see Block an authorization provider.

  3. Define a redirection in case users are not logged in.

    Azure Static Web Apps returns a status code 401 when a user who is not logged in tries to access a page available only to authenticated users. You can redirect users from the default error page to a login page using the responseOverrides element. For more information, see Response overrides.

    In this example, the staticwebapp.config.json file looks like this:
    {
        "routes": [
            {
                "route": "/login",
                "rewrite": "/.auth/login/aad"
            },
            {
                "route": "/logout",
                "redirect": "/.auth/logout"
            },
            {
                "route": "/me",
                "redirect": "/.auth/me"
            },
            {
                "route": "/apis/*",
                "allowedRoles": ["api_developer"]
            },
            {
                "route": "/getting-started",
                "allowedRoles": ["api_developer"]
            },
            {
                "route": "/*",
                "allowedRoles": ["authenticated"]
            }
        ],
        "responseOverrides": {
            "401": {
                "redirect": "/login",
                "statusCode": 302
            }
        }
    }
  4. Commit your changes.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!