lib/osso/routes/oauth.rb in osso-0.0.7 vs lib/osso/routes/oauth.rb in osso-0.0.8

- old
+ new

@@ -14,17 +14,18 @@ # of the user who wants to sign in. If the sign in request # is valid, the user is redirected to their Identity Provider. # Once they complete IdP login, they will be returned to the # redirect_uri with an authorization code parameter. get '/authorize' do - identity_providers = find_providers - validate_oauth_request(env) - redirect "/auth/saml/#{identity_providers.first.id}" if identity_providers.one? + return erb :hosted_login if render_hosted_login? - @providers = identity_providers.not_pending + @providers = find_providers + + redirect "/auth/saml/#{@providers.first.id}" if @providers.one? + return erb :multiple_providers if @providers.count > 1 raise Osso::Error::MissingConfiguredIdentityProvider.new(domain: params[:domain]) rescue Osso::Error::Base => e @error = e @@ -59,19 +60,24 @@ end end private + def render_hosted_login? + [params[:email], params[:domain]].all?(&:nil?) + end + def find_providers if params[:email] user = Osso::Models::User. includes(:identity_provider). find_by(email: params[:email]) return [user.identity_provider] if user end Osso::Models::IdentityProvider. joins(:oauth_client). + not_pending. where( domain: domain_from_params, oauth_clients: { identifier: params[:client_id] }, ) end