-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Token required even when not necessary #190
Comments
Also discussed here: #86 - but added this issue anyway as a feature request. |
@MicMicMon - If you just need to use the Authentication API endpoints, you can require the gem and only pull in the component you need. Here is a quick example: require 'auth0'
# SessionsController - login and logout controller.
# Handles the session creation in the app and Auth0 redirects.
class SessionsController < ApplicationController
# Ruby SDK auth flow
def new
extend Auth0::Api::AuthenticationEndpoints
options = {
scope: 'openid email offline_access',
state: SecureRandom.hex(16)
}
session[:auth0_state] = options[:state]
redirect_to authorization_url(callback_url, options).to_s
end
end |
Ah yes, thanks for the idea. Still, I'm not so keen on pulling chunks of code from a gem - that might change - inside my own code. Specifying Offering this hassle-free token creation through a Singleton-like class would be a very nice wrapper I think. |
Anything that's a public API, this in particular, will not change. We would expect someone to use the pieces they need.
This was just an example of how that module can be pulled in to use, I don't know what method you're trying to use there. State can be random, like this, or it can contain actual state information (page to return to, shopping cart ID, etc) so it might actually be something that a developer would want to control.
I'm not sure I follow. You said you wanted to use this without a token ... am I missing something? Thank you! |
Yes ok I get it, it just pulls much more than I actually need into my own object - which I don't like that much. I prefer having a specific object outside that does not impact my own object signature. Sorry I wasn't clear: I need a token once I get it. My need is:
Thus, a singleton object that achieves step 1 would be nice. That would replace class Auth0ManagementAPI
include Singleton
def auth0_api
@auth0_api ||= Auth0Client.new(
client_id: Rails.application.secrets.auth0_client_id,
domain: Rails.application.secrets.auth0_domain,
token: mtom_api_token.access_token,
api_version: 2
)
end
# Return a fresh token for the Backend to interact with the Auth0 Management
# API
#
# @return [ApiToken]
def mtom_api_token
Auth0Client.new(
client_id: Rails.application.secrets.auth0_client_id,
client_secret: Rails.application.secrets.auth0_api_mtom_client_secret,
domain: Rails.application.secrets.auth0_domain,
token: 'dummy-but-must-be-non-null-because-of-the-gem'
).api_token
end Then I simply use it (that's only then that I need the token): # Updates user metadata (the user typically can modify this metadata through
# the UI).
#
# @param [String] user_id
# @param [Hash] user_metadata
#
# @return [Hash] Updated user profile from Auth0
def update_user_metadata(user_id, user_metadata)
# Clears first, otherwise merges only
auth0_api.patch_user(user_id, user_metadata: {})
auth0_api.patch_user(user_id, user_metadata: user_metadata)
end Hope it's more clear that way. It's definitely ok, I was just suggesting an improvement for the gem API - or maybe I don't know some classic pattern that you normally use in that case. Including the gem code inside my methods seems anti-pattern to me but I could well be wrong. |
I'm not clear why you're calling the |
There must be something I don't understand. What do you mean by "the token that's automatically retrieved"? If I replace my def auth0_api
@auth0_api ||= Auth0Client.new(
client_id: Rails.application.secrets.auth0_client_id,
domain: Rails.application.secrets.auth0_domain,
# token: mtom_api_token.access_token,
api_version: 2
)
end I sure get this: That's why I generate a token in the first place, following the instructions here. What am I missing here? |
Ah ... that exception is not indicating that you can include the Example: # ...
def auth0_api
@auth0_api ||= Auth0Client.new(
client_id: Rails.application.secrets.auth0_client_id,
domain: Rails.application.secrets.auth0_domain,
client_secret: Rails.application.secrets.auth0_client_secret,
api_version: 2
)
end
# ... I'll leave this open to make sure that gets done. Apologies for the gap in documentation here! |
Awesome, thanks for the clarification! (I leave it open for you to close when you're comfortable) |
@MicMicMon - Thanks again for the report here. Would you mind taking a quick look at the PR and see if those instructions would have helped you earlier in the process? |
Sorry, didn't look at it until now. That's great, it is now totally clear I think :) |
@qortex and @joshcanhelp sorry to bring this up again. I'm trying to use the But when I do that with my
But to use the So I have two options:
My question is, there is a better way to do use the |
The gem requires the token to be non-null (see this line), whereas it is useful to use the API (specifically those helpers) just to actually get a management token - and thus with a nil token to begin with.
I have this workaround for now, but that would be great to provide a canonical way (or maybe there is and I didn't think of it?):
The text was updated successfully, but these errors were encountered: