Hey Community!
I hope everything is going well.
Background:
I have an M2M application that generates new M2Ms for API consumption. The newly created M2M needs to have my API identifier grants.
I am receiving this error:
The client is not authorized to access "API-IDENTIFIER". You need to create a \"client-grant\" associated with this API
- I know I can manually change it by going to the dashboard.
Question:
How can I grant API authorization while generating new M2M so I don’t have to authorize it manually?
export const postApiRegistration = async (registrationDetails): Promise<Auth0Connection> => {
const token = await getAuth0ManagementToken();
const url = `${AUTH0_BASE_URL}/api/v2/clients`;
const DATAHUB_API_ID = 'DATAHUB_API_ID ';
let data = JSON.stringify({
name: registrationDetails.AppName,
description: `Auth0 Generic Api registration ${registrationDetails.CustomerCode}`,
callbacks: [],
client_aliases: [],
allowed_clients: [`${DATAHUB_API_ID}`],
grant_types: ['client_credentials'],
token_endpoint_auth_method: 'client_secret_post',
app_type: 'non_interactive',
is_first_party: true,
oidc_conformant: false,
jwt_configuration: {
lifetime_in_seconds: 36000,
scopes: {},
alg: 'RS256',
secret_encoded: false
},
cross_origin_authentication: false,
sso_disabled: false,
custom_login_page_on: true,
native_social_login: {
apple: {
enabled: false
},
facebook: {
enabled: false
}
},
refresh_token: {
expiration_type: 'non-expiring',
leeway: 0,
infinite_token_lifetime: true,
infinite_idle_token_lifetime: true,
token_lifetime: 31557600,
idle_token_lifetime: 2592000,
rotation_type: 'non-rotating'
}
});
const options: AxiosRequestConfig = {
url: url,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${token.access_token}`
},
data: data
};
const connectionsResponse = await axios.request<Auth0Connection>(options);
return connectionsResponse.data;
};