1

I am trying to delete a user based on id, on auth0 API v2 they give only the curl command. For the post method I managed to adapt it to angular2 http post, for some reason I cannot figure out how to use the delete request.

the id looks like this

id = auth0|582b40627882b2970253725c

This is the method I am using:

deleteAuth0User(id){
let headers = new Headers();
headers.append('Authorization', 'Bearer mytoken');
return this.http.delete('https://myusername.eu.auth0.com/api/v2/users/' + id, {headers:headers})
.map(response => response.json());
}

I have removed my auth0 username and api token.

I get this error as a result:

"{"statusCode":403,"error":"Forbidden","message":"Insufficient scope, expected any of: delete:users,delete:current_user","errorCode":"insufficient_scope"}"

Any suggestion much appreciated. Thank you

P.S. If you are interested in the post method for adding a new user:

createAuth0User(body){

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization', 'Bearer myapitoken');
    return this.http.post('https://myusername.eu.auth0.com/api/v2/users', JSON.stringify(body),{headers:headers})
      .map(response => response.json());
  }
Avram Virgil
  • 1,170
  • 11
  • 22
  • Avram, pleased you sorted it out! Have dropped in a quick "answer" to suggest an easy way to get template code too. – arcseldon Nov 16 '16 at 01:56
  • or rather you can create a singleton token generation method to use the same token within the application. – Zubair Nabi Nov 16 '16 at 17:16

2 Answers2

1

I managed to figure it out, with the Auth0 API v2 each time you add to the scope an option a new token is generated, you can add multiple options to the scope so you can use the same token for all of them.

The 2nd thing with the Auth0 API v2 on http delete you cannot use .map because you will get a:

json parsing error syntax error unexpected end of input

The working method is:

deleteAuth0User(id){
let headers = new Headers();
headers.append('Authorization', 'Bearer mytoken');
return this.http.delete('https://myusername.eu.auth0.com/api/v2/users/' + id, {headers:headers})
}

This will work, do not forget to subscribe in the component you are using the method because you will still get a response back.

Avram Virgil
  • 1,170
  • 11
  • 22
1

One easy way to get the code you require is by using Postman. Then you can simply import the Curl command into Postman (using import option) and / or generate the required JavaScript (client side) / NodeJs code (using Postman's code option).

See screenshots below:

enter image description here

and

enter image description here

Finally, you can get pre-built template Postman commands for all Auth0's Authentication API and Management APIv2 endpoints.

See the downloads options here

arcseldon
  • 35,523
  • 17
  • 121
  • 125