2016-11-15 75 views
1

我想刪除一個基於id的用戶,在auth0 API v2上他們只給出curl命令。對於post方法,我設法將其修改爲angular2 http post,出於某種原因,我無法弄清楚如何使用刪除請求。用Auth0刪除用戶apiv2

的ID看起來像這樣

id = auth0|582b40627882b2970253725c 

這是我使用的方法:

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()); 
} 

我已刪除了我的auth0的用戶名和API令牌。

我得到這個錯誤的結果:

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

任何建議非常讚賞。 謝謝

P.S.如果你有興趣在POST方法添加新用戶:每次添加的範圍產生一個新的令牌選項時

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()); 
    } 
+0

Avram,很高興你整理出來!已經下降了一個快速的「答案」,建議一個簡單的方法來獲取模板代碼。 – arcseldon

+0

或者您可以創建一個單例令牌生成方法,以在應用程序中使用相同的令牌。 –

回答

1

我設法弄明白,與Auth0 API第2版,您可以向範圍添加多個選項,以便您可以對所有這些選項使用相同的標記。

與HTTP的Auth0 API第2版第2件事刪除你不能使用.MAP因爲你會得到一個:

json parsing error syntax error unexpected end of input 

的工作方法是:

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}) 
} 

這將工作,做不要忘記在你使用該方法的組件中訂閱,因爲你仍然會得到迴應。

1

獲取所需代碼的一種簡單方法是使用Postman。然後,您可以簡單地將Curl命令導入Postman(使用import選項)和/或生成所需的JavaScript(客戶端)/ NodeJs代碼(使用Postman的code選項)。

見下截圖:

enter image description here

enter image description here

最後,你可以得到所有Auth0的Authentication APIManagement APIv2端點預建的模板郵差命令。

查看下載選項here