Module: MicroAuth::AuthenticationHelper
- Defined in:
- app/helpers/micro_auth/authentication_helper.rb
Instance Method Summary collapse
-
#authenticated_user_object(token) ⇒ Hash{Symbol => Object}
Provides a hash of user data based on what data the provided token is scoped to access.
-
#construct_redirect(redirect_uri, **params) ⇒ String
Builds a redirect URI, adding specified parameters as necessary.
-
#valid_auth_scopes ⇒ Hash{String => String}
Contains all valid scopes for authentication requests.
Instance Method Details
#authenticated_user_object(token) ⇒ Hash{Symbol => Object}
Provides a hash of user data based on what data the provided token is scoped to access. For instance, :email
will only be included when a pii
scoped token is presented.
30 31 32 33 34 35 |
# File 'app/helpers/micro_auth/authentication_helper.rb', line 30 def authenticated_user_object(token) fields = [:id, :created_at, :is_global_moderator, :is_global_admin, :username, :website, :twitter, :staff, :developer, :discord] fields << :email if token.scope.include? 'pii' fields.to_h { |f| [f, token.user.send(f)] } end |
#construct_redirect(redirect_uri, **params) ⇒ String
Builds a redirect URI, adding specified parameters as necessary.
18 19 20 21 22 23 |
# File 'app/helpers/micro_auth/authentication_helper.rb', line 18 def construct_redirect(redirect_uri, **params) uri = URI(redirect_uri) query = URI.decode_www_form(uri.query || '').to_h.merge(params) uri.query = URI.encode_www_form(query.to_a) uri.to_s end |
#valid_auth_scopes ⇒ Hash{String => String}
Contains all valid scopes for authentication requests. A ‘nil` description indicates a scope that is not displayed to the user during authentication requests.
6 7 8 9 10 11 |
# File 'app/helpers/micro_auth/authentication_helper.rb', line 6 def valid_auth_scopes { 'perpetual' => nil, 'pii' => 'Access to personal information (including email address)' } end |