Hello,
I have integrated auth0 in my rails application. Signup & Signin working fine with auth0. But I cannot delete user from auth0 by user_id.
FYI: access_token, user_id all these details are correct.
-
Getting 400 Bad Request error when using below details in delete api
method: DELETE
userid: 7das1k5n54b56t6c126b9rh4
URL: https://my-xyz-domain.auth0.com/api/v2/users/userid
headers: Content-Type => application/json, Authorization => Bearer access_token
-
Getting bad URI error when using below details
method: DELETE
userid: auth0|7das1k5n54b56t6c126b9rh4
URL: https://my-xyz-domain.auth0.com/api/v2/users/userid
headers: Content-Type => application/json, Authorization => Bearer access_token
Please help asap.
Hey there!
Can you share with us the code snippet that you use to delete the user? Thank you a lot!
Hi
Here is the code:
token_params = {"grant_type" => ENV["GRANT_TYPE"],"client_id" => ENV['CLIENT_ID'],"client_secret" => ENV['CLIENT_SECRET'], "audience" => ENV["AUDIENCE"]}
token_response = RestClient::Request.execute(method: :post, url: ENV["DOMAIN_NAME"]+"/oauth/token", payload: token_params, headers: {"Content-Type" => "application/json"} )
all_token_response_values = JSON.parse(token_response)
access_token = all_token_response_values["access_token"]
token_type = all_token_response_values["token_type"]
@user = User.find(params[:id])
get_user_response = RestClient::Request.execute(method: :get, url: ENV["DOMAIN_NAME"]+"/api/v2/users-by-email?email=#{@user.email}", headers: {"Content-Type" => "application/json", "Authorization" => token_type+" "+access_token})
@user_parse = JSON.parse(get_user_response)
@auth0_user_id = @user_parse[0]['identities'][0]['user_id']
url = ENV["DOMAIN_NAME"]+"/api/v2/users/#{@auth0_user_id}"
delete_user_response = RestClient::Request.execute(method: :DELETE, url: url, headers: {"Content-Type" => "application/json", "Authorization" => token_type+" "+access_token})
@deleted_user = JSON.parse(delete_user_response)
`
I am also getting same issue while updating user details by update API.
I found solution for this issue.
User ID must be include auth0. So it looks like “userid: auth0|7das1k5n54b56t6c126b9rh4”.
And url should be wrapped with URI::escape().
So it look like URI::escape(https://my-xyz-domain.auth0.com/api/v2/users/userid).
Auth0 don’t mention this in document.
Perfect! Glad you have figured it out! I will relay that info to our docs team.