# Service not enabled within domain after switch to custom domain when onboarding new users

**URL:** <https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062>\
**Category:** Get Help\
**Tags:** custom-domains, management-api\
**Created:** [January 3, 2024, 2:26pm UTC](https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062 "2024-01-03T14:26:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![konrad.galczynski](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@konrad.galczynski](https://community.auth0.com/u/konrad.galczynski)\
**Post date:** [January 3, 2024, 2:26pm UTC](https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062/1 "2024-01-03T14:26:09Z")

</div>

Hello,

I have following setup:

- asp net core app with custom domain set in configuration via openid connect with following code:  
.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =\>  
{  
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;  
options.SignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;  
options.ResponseType = OpenIdConnectResponseType.IdToken;  
options.CallbackPath = “/”;  
options.UsePkce = true;

- auth0 with custom domain in place

- two custom action wich are assigning roles to users upon login and password reset and use management API to do so

Everything works like a charm except onboarding new users. When user is created and tries to access app for the first time I can see in the Auth0 logs following message: Failed Exchange: Service not enabled within domain: [https://mydomain/api/v2/](https://mydomain/api/v2/). In both my actions i am creating management API like this:

```
const management = new ManagementClient({
  domain: event.secrets.domain,
  clientId: event.secrets.clientId,
  clientSecret: event.secrets.clientSecret,
  scope: "read:roles",
});

```

where domain is ‘old’ domain, not custom one. Can you point out what I am doing wrong here?  
For old users both login and password change works fine

---

<div class="post-metadata">

**Author:** ![konrad.galczynski](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@konrad.galczynski](https://community.auth0.com/u/konrad.galczynski)\
**Post date:** [January 3, 2024, 2:40pm UTC](https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062/2 "2024-01-03T14:40:34Z")

</div>

In addition to this when I compare successful exchange (for existing user) and failed exchange (for new user) I can see that failed exchange in hostname nad audience contains my custom domain whereas successful exchange in hostname and audience contains ‘old’ domain

---

<div class="post-metadata">

**Author:** ![konrad.galczynski](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@konrad.galczynski](https://community.auth0.com/u/konrad.galczynski)\
**Post date:** [January 4, 2024, 10:10am UTC](https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062/3 "2024-01-04T10:10:52Z")

</div>

I have managed to fix this so I will leave answer here. What helped was following code:

```
        options.Events.OnRedirectToIdentityProvider = context =>
        {
            context.ProtocolMessage.SetParameter("audience", configuration["Auth0Audience"]);
            // logic
        }

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 18, 2024, 10:11am UTC](https://community.auth0.com/t/service-not-enabled-within-domain-after-switch-to-custom-domain-when-onboarding-new-users/124062/4 "2024-01-18T10:11:04Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
