How can I get the token value from a Auth0Client instance? I am using ruby-auth0 gem, I can instantiate the client with client id, secret and domain and see the generated token in rails console
. But I couldn’t find a reader method to retrieve that token and reuse it in subsequent API calls.
Hey @joao.roberto thanks for your comment!
I was going trough the gem. and you’re right, there’s no getter for the token (I will ask internally about this). Although if you want to use it for subsequent calls you can reuse the client instance you have, for example:
You can create a method for the client like so:
def auth0_client
client ||= Auth0Client.new(client_id: AUTH0_CONFIG['auth0_client_id'],
client_secret: AUTH0_CONFIG['auth0_client_secret'],
domain: AUTH0_CONFIG['auth0_domain'])
client
end
and then when you need to call different API endpoints you can use the auth0_client
method like so:
def get_auth_methods(auth0_user_id)
# Get all authentication methods from a user
# https://auth0.com/docs/api/management/v2/users/get-authentication-methods
authentication_methods = auth0_client.user_authentication_methods(auth0_user_id)
# ...
end
def delete_auth_method(auth0_method_id, auth0_user_id)
# Revoke passkey from Auth0
# https://auth0.com/docs/api/management/v2/users/delete-authentication-methods-by-authentication-method-id
auth0_client.delete_user_authentication_method(auth0_user_id, auth0_method_id)
end
Let me know if you have further questions!