mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
New accounts only from an administrator or an administrator's invitation
Anyone can add an aircraft and so manage its people, so invitations from non-administrators could bring in new accounts without an administrator. - An invitation makes a new account only if whoever made it is still an administrator when it's used; an aircraft's Access page invitations are for people who already have an account (its welcome page says so). - Signing invitations no longer make accounts: the mechanic needs one first, and the owner is told when they don't have one. - With SSO, "Continue with <provider>" on an administrator's invitation makes the account and accepts the invitation (only for its address when it has one), so invitations work without OIDC_AUTO_CREATE_USERS. That setting stays, documented as giving accounts without an invitation; the Authentik example now leaves it off. - Docs: who makes accounts (guide, README, Authentik, .env.example, API). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4c7aaa3ff
commit
19bc3efa19
19 files changed
+159
-85
No files matched your search
@@ -6,6 +6,10 @@
|
||||
# email is verified (or OIDC_TRUST_EMAIL is on), since some providers let
|
||||
# users edit their email. Otherwise, sign in with a password once and link
|
||||
# from the profile page.
|
||||
#
|
||||
# Someone without an account gets one only from an administrator's
|
||||
# invitation they opened first (AccessInvitation, accepted at once), or for
|
||||
# anyone the provider lets in when OIDC_AUTO_CREATE_USERS is on.
|
||||
class SsoController < ApplicationController
|
||||
allow_unauthenticated_access only: %i[callback failure]
|
||||
before_action :require_sso
|
||||
@@ -29,6 +33,7 @@ class SsoController < ApplicationController
|
||||
return_to = session[:return_to_after_authenticating]
|
||||
reset_session # fresh session id after signing in
|
||||
start_new_session_for user
|
||||
return redirect_to(root_url, notice: [ t("flash.joins.welcome"), AccessInvitation.describe(@joined) ].join(" ").strip) if @joined
|
||||
redirect_to return_to || root_url
|
||||
end
|
||||
|
||||
@@ -81,15 +86,27 @@ class SsoController < ApplicationController
|
||||
end
|
||||
|
||||
def create_user(auth)
|
||||
return unless Sso.auto_create_users?
|
||||
email = auth.info&.email.to_s.strip.downcase
|
||||
return if email.blank? || User.exists?(email_address: email)
|
||||
# The random password is never shown; a password reset can set a real one.
|
||||
User.create!(email_address: email, name: auth.info&.name.presence, sso_uid: auth.uid, password: SecureRandom.base58(40))
|
||||
invitation = invitation_making_account(email)
|
||||
return unless invitation || Sso.auto_create_users?
|
||||
User.transaction do
|
||||
# The random password is never shown; a password reset can set a real one.
|
||||
user = User.create!(email_address: email, name: auth.info&.name.presence, sso_uid: auth.uid, password: SecureRandom.base58(40))
|
||||
@joined = invitation&.redeem!(user)
|
||||
user
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
nil
|
||||
end
|
||||
|
||||
# The invitation opened in this browser before signing in, when it can
|
||||
# make an account (an administrator's) for this email address.
|
||||
def invitation_making_account(email)
|
||||
invitation = AccessInvitation.find_by_token(session[:join_token])
|
||||
invitation if invitation&.usable? && invitation.creates_accounts? && invitation.for_email?(email)
|
||||
end
|
||||
|
||||
def email_verified?(auth)
|
||||
[ true, "true" ].include?(raw_info(auth)["email_verified"])
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user