source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/signin_permissions_controller.rb
Ruby
mit
97
main
1,680
class Users::SigninPermissionsController < ApplicationController before_action :authenticate_user! before_action :set_user before_action :set_application, except: [:create] include ApplicationAccessHelper def create application = Doorkeeper::Application.not_api_only.find(params[:application_id]) aut...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/invitation_resends_controller.rb
Ruby
mit
97
main
832
class Users::InvitationResendsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_if_invitation_already_accepted def edit; end def update @user.invite!(current_user) EventLog.record_account_invitation(@...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/two_step_verification_resets_controller.rb
Ruby
mit
97
main
732
class Users::TwoStepVerificationResetsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] def edit; end def update @user.reset_2sv!(current_user) Us...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/permissions_controller.rb
Ruby
mit
97
main
3,680
class Users::PermissionsController < ApplicationController before_action :authenticate_user! before_action :set_user before_action :set_application before_action :set_permissions, only: %i[edit update] include ApplicationPermissionsHelper def show authorize [{ application: @application, user: @user }]...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/two_step_verification_mandations_controller.rb
Ruby
mit
97
main
617
class Users::TwoStepVerificationMandationsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user def edit; end def update user_params = { require_2sv: true } updater = UserUpdate.new(@user, user_params, current_user, user_ip_addres...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/applications_controller.rb
Ruby
mit
97
main
597
class Users::ApplicationsController < ApplicationController before_action :authenticate_user! def show user = User.find(params[:user_id]) authorize [{ user: }], policy_class: Users::ApplicationPolicy redirect_to user_applications_path(user) end def index @user = User.find(params[:user_id]) ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/names_controller.rb
Ruby
mit
97
main
1,108
class Users::NamesController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] helper_method :submit_path helper_method :return_path def edit; end def update ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/organisations_controller.rb
Ruby
mit
97
main
857
class Users::OrganisationsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] def edit; end def update updater = UserUpdate.new(@user, user_params, curr...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/emails_controller.rb
Ruby
mit
97
main
1,556
class Users::EmailsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] helper_method :submit_path helper_method :return_path def edit; end def update ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/unlockings_controller.rb
Ruby
mit
97
main
783
class Users::UnlockingsController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_if_already_unlocked def edit; end def update @user.unlock_access! EventLog.record_event(@user, EventLog::MANUAL_ACCOUNT_UNLOCK,...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/users/roles_controller.rb
Ruby
mit
97
main
822
class Users::RolesController < ApplicationController before_action :authenticate_user! before_action :load_user before_action :authorize_user before_action :redirect_to_account_page_if_acting_on_own_user, only: %i[edit] def edit; end def update updater = UserUpdate.new(@user, user_params, current_user...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/api_users/applications_controller.rb
Ruby
mit
97
main
296
class ApiUsers::ApplicationsController < ApplicationController before_action :authenticate_user! def index @api_user = ApiUser.find(params[:api_user_id]) authorize @api_user @applications = @api_user.authorised_applications.merge(Doorkeeper::AccessToken.not_revoked) end end
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/api_users/permissions_controller.rb
Ruby
mit
97
main
1,185
class ApiUsers::PermissionsController < ApplicationController before_action :authenticate_user! before_action :set_user before_action :set_application before_action :set_permissions def edit authorize @api_user end def update authorize @api_user supported_permission_ids = UserUpdatePermissi...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/applications_controller.rb
Ruby
mit
97
main
493
class Account::ApplicationsController < ApplicationController before_action :authenticate_user! def show authorize [:account, Doorkeeper::Application] redirect_to account_applications_path end def index authorize [:account, Doorkeeper::Application] @applications_with_signin = Doorkeeper::App...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/organisations_controller.rb
Ruby
mit
97
main
648
class Account::OrganisationsController < ApplicationController before_action :authenticate_user! before_action :authorise_user def edit; end def update organisation_id = params[:user][:organisation_id] organisation = Organisation.find(organisation_id) if UserUpdate.new(current_user, { organisatio...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/roles_controller.rb
Ruby
mit
97
main
541
class Account::RolesController < ApplicationController before_action :authenticate_user! before_action :authorise_user def edit; end def update role = params[:user][:role] if UserUpdate.new(current_user, { role: }, current_user, user_ip_address).call redirect_to account_path, notice: "Your role...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/signin_permissions_controller.rb
Ruby
mit
97
main
1,254
class Account::SigninPermissionsController < ApplicationController before_action :authenticate_user! include ApplicationAccessHelper def create authorize [:account, Doorkeeper::Application], :grant_signin_permission? params = { supported_permission_ids: current_user.supported_permissions.map(&:id) + [a...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/permissions_controller.rb
Ruby
mit
97
main
3,392
class Account::PermissionsController < ApplicationController before_action :authenticate_user! before_action :set_application before_action :set_permissions, only: %i[edit update] include ApplicationPermissionsHelper def show authorize [:account, @application], :view_permissions? @permissions = @ap...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/emails_controller.rb
Ruby
mit
97
main
1,312
class Account::EmailsController < ApplicationController before_action :authenticate_user! before_action :authorise_user def edit; end def update current_email = current_user.email new_email = params[:user][:email] if current_email == new_email.strip flash[:alert] = "Nothing to update." ...
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/activities_controller.rb
Ruby
mit
97
main
289
class Account::ActivitiesController < ApplicationController before_action :authenticate_user! before_action :authorise_user def show @logs = current_user.event_logs.page(params[:page]).per(100) end private def authorise_user authorize %i[account activities] end end
github
alphagov/signon
https://github.com/alphagov/signon
app/controllers/account/passwords_controller.rb
Ruby
mit
97
main
824
class Account::PasswordsController < ApplicationController before_action :authenticate_user! before_action :authorise_user def edit; end def update if current_user.update_with_password(password_params) EventLog.record_event(current_user, EventLog::SUCCESSFUL_PASSWORD_CHANGE, ip_address: user_ip_addr...
github
alphagov/signon
https://github.com/alphagov/signon
app/queries/users_with_access.rb
Ruby
mit
97
main
534
class UsersWithAccess attr_reader :scope, :application def initialize(scope, application) @scope = scope @application = application end def users scope .where(id: authorized_users_user_ids) .includes(:organisation, application_permissions: :supported_permission) .order("current_s...
github
alphagov/signon
https://github.com/alphagov/signon
app/mailers/noisy_batch_invitation.rb
Ruby
mit
97
main
609
class NoisyBatchInvitation < ApplicationMailer include MailerHelper default from: proc { email_from } default to: I18n.t("noisy_batch_invitation_mailer.to") def make_noise(batch_invitation) @user = batch_invitation.user @batch_invitation = batch_invitation user_count = batch_invitation.batch_invi...
github
alphagov/signon
https://github.com/alphagov/signon
app/mailers/mailer_helper.rb
Ruby
mit
97
main
447
module MailerHelper def email_from "#{app_name} <#{email_from_address}>" end def app_name I18n.t("mailer.app_name.instance", instance_name: GovukEnvironment.current) end def email_from_address if GovukEnvironment.current == "production" I18n.t("mailer.email_from_address.no_instance") e...
github
alphagov/signon
https://github.com/alphagov/signon
app/mailers/user_mailer.rb
Ruby
mit
97
main
4,057
class UserMailer < Devise::Mailer include MailerHelper append_view_path Rails.root.join("app/views/devise/mailer") default from: proc { email_from } helper_method :suspension_time, :account_name, :locked_time, :unlock_time def two_step_reset(user) @user = user view_mail(template_id, to: @user.email...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/batch_invitation.rb
Ruby
mit
97
main
1,310
class BatchInvitation < ApplicationRecord belongs_to :user belongs_to :organisation has_many :batch_invitation_users, -> { order(:name) } has_many :batch_invitation_application_permissions, inverse_of: :batch_invitation has_many :supported_permissions, through: :batch_invitation_application_permissions ser...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/users_filter.rb
Ruby
mit
97
main
3,233
class UsersFilter CHECKBOX_FILTER_KEYS = %i[statuses two_step_statuses roles permissions organisations].freeze PERMITTED_CHECKBOX_FILTER_PARAMS = CHECKBOX_FILTER_KEYS.each.with_object({}) { |k, h| h[k] = [] }.freeze attr_reader :options def initialize(users, current_user, options = {}) @users = users ...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/api_user.rb
Ruby
mit
97
main
674
class ApiUser < User default_scope { where(api_user: true).order(:name) } validate :reason_for_2sv_exemption_blank validate :require_2sv_is_false DEFAULT_TOKEN_LIFE = 2.years.to_i def self.build(attributes = {}) password = SecureRandom.urlsafe_base64 new(attributes.merge(password:, password_confirm...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/user_application_permission.rb
Ruby
mit
97
main
731
class UserApplicationPermission < ApplicationRecord belongs_to :user belongs_to :application, class_name: "Doorkeeper::Application" belongs_to :supported_permission validates :user, :supported_permission, :application, presence: true validates :supported_permission_id, uniqueness: { scope: %i[user_id applica...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/two_step_verification_exemption.rb
Ruby
mit
97
main
1,592
class TwoStepVerificationExemption include ActiveModel::Model include ActiveModel::Attributes attribute :reason, :string attribute :expiry_day, :string attribute :expiry_month, :string attribute :expiry_year, :string attr_reader :expiry_date validates :reason, presence: { message: "must be provided" ...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/event_log.rb
Ruby
mit
97
main
9,344
require "ipaddr" class EventLog < ApplicationRecord LOCKED_DURATION = User.unlock_in.inspect.freeze EVENTS = [ ACCOUNT_LOCKED = LogEntry.new(id: 1, description: "Password verification failed too many times, account locked for #{LOCKED_DURATION}", require_uid: true), ACCOUNT_SUSPENDED = LogEntry.new(id: 2,...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/user.rb
Ruby
mit
97
main
15,739
class User < ApplicationRecord include Roles self.include_root_in_json = true NEVER_SIGNED_IN_EXPIRY_PERIOD = 90.days SUSPENSION_THRESHOLD_PERIOD = 45.days UNSUSPENSION_GRACE_PERIOD = 7.days MAX_2SV_LOGIN_ATTEMPTS = 10 REMEMBER_2SV_SESSION_FOR = 30.days USER_STATUS_SUSPENDED = "suspended".freeze ...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/legacy_users_filter.rb
Ruby
mit
97
main
1,066
class LegacyUsersFilter PARAM_KEYS = %i[status two_step_status role permission organisation].freeze LEGACY_TWO_STEP_STATUS_VS_TWO_STEP_STATUS = { "true" => User::TWO_STEP_STATUS_ENABLED, "false" => User::TWO_STEP_STATUS_NOT_SET_UP, "exempt" => User::TWO_STEP_STATUS_EXEMPTED, }.freeze def initialize...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/organisation.rb
Ruby
mit
97
main
960
class Organisation < ApplicationRecord GDS_ORG_CONTENT_ID = "af07d5a5-df63-4ddc-9383-6a666845ebe9".freeze NONE = "None".freeze has_ancestry has_many :users validates :slug, presence: true, uniqueness: { case_sensitive: true } validates :content_id, presence: true validates :name, presence: true valid...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/reject_non_governmental_email_addresses_validator.rb
Ruby
mit
97
main
686
class RejectNonGovernmentalEmailAddressesValidator < ActiveModel::EachValidator NON_GOVERNMENTAL_EMAIL_DOMAIN_KEYWORDS = %w[ aol btinternet gmail hotmail outlook yahoo ].freeze MESSAGE = "not accepted. Please enter a workplace email to continue.".freeze def validate_each(record, attribute, value) retu...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/suspension.rb
Ruby
mit
97
main
940
class Suspension include ActiveModel::Validations validates :reason_for_suspension, presence: true, if: :suspend attr_reader :suspend, :reason_for_suspension, :user, :initiator, :ip_address def initialize(suspend: nil, reason_for_suspension: nil, user: nil, initiator: nil, ip_address: nil) @suspend = susp...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/log_entry.rb
Ruby
mit
97
main
599
class LogEntry attr_reader :id, :description def initialize(id:, description:, require_uid: false, require_initiator: false, require_application: false, access_limited: false) @id = id @description = description @require_uid = require_uid @require_initiator = require_initiator @require_applicat...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/supported_permission.rb
Ruby
mit
97
main
1,308
class SupportedPermission < ApplicationRecord SIGNIN_NAME = "signin".freeze belongs_to :application, class_name: "Doorkeeper::Application" has_many :user_application_permissions, dependent: :destroy, inverse_of: :supported_permission validates :name, presence: true, uniqueness: { scope: :application_id } va...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/batch_invitation_application_permission.rb
Ruby
mit
97
main
362
class BatchInvitationApplicationPermission < ApplicationRecord belongs_to :batch_invitation, inverse_of: :batch_invitation_application_permissions belongs_to :supported_permission validates :batch_invitation, :supported_permission, presence: true validates :supported_permission_id, uniqueness: { scope: :batch_...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/batch_invitation_user.rb
Ruby
mit
97
main
3,010
class BatchInvitationUser < ApplicationRecord belongs_to :batch_invitation validates :email, presence: true, format: { with: Devise.email_regexp } validates :email, reject_non_governmental_email_addresses: true validates :outcome, inclusion: { in: [nil, "success", "failed", "skipped"] } before_save :strip_...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/user_update_permission_builder.rb
Ruby
mit
97
main
594
class UserUpdatePermissionBuilder def initialize(user:, updatable_permission_ids:, selected_permission_ids:) @user = user @updatable_permission_ids = updatable_permission_ids @selected_permission_ids = selected_permission_ids end def build permissions_user_has = @user.supported_permissions.pluck(...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/doorkeeper/application.rb
Ruby
mit
97
main
3,517
require "doorkeeper/orm/active_record/application" class Doorkeeper::Application < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord has_many :supported_permissions, dependent: :destroy has_many :event_logs, class_name: "EventLog" default_scope { not_retired.ordered_by_name } scope :ordered_by_nam...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/doorkeeper/access_token.rb
Ruby
mit
97
main
715
module Doorkeeper class AccessToken < ::ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord scope :not_revoked, -> { where(revoked_at: nil) } scope :expires_after, ->(time) { where.not(expires_in: nil).where("#{sanitize_sql(expiration_time_sql)} > ?", time) } scope :expires_before, ->(time) { whe...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/doorkeeper/after_successful_authorization_processor.rb
Ruby
mit
97
main
643
module Doorkeeper class AfterSuccessfulAuthorizationProcessor def initialize(controller, context) @controller = controller @context = context end def process return unless @controller.instance_of?(Doorkeeper::TokensController) return unless application && user EventLog.reco...
github
alphagov/signon
https://github.com/alphagov/signon
app/models/doorkeeper/access_grant.rb
Ruby
mit
97
main
274
module Doorkeeper class AccessGrant < ::ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord include Models::ExpirationTimeSqlMath scope :expired, -> { where.not(expires_in: nil).where("#{sanitize_sql(expiration_time_sql)} < ?", Time.current) } end end
github
alphagov/signon
https://github.com/alphagov/signon
lib/inactive_users_suspension_reminder.rb
Ruby
mit
97
main
1,590
class InactiveUsersSuspensionReminder ERRORS_TO_RETRY_ON = [Timeout::Error, SocketError, Net::SMTPServerBusy, Errno::ETIMEDOUT, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, EOFE...
github
alphagov/signon
https://github.com/alphagov/signon
lib/user_parameter_sanitiser.rb
Ruby
mit
97
main
1,027
class UserParameterSanitiser def initialize(user_params:, current_user_role:, permitted_params_by_role: default_permitted_params_by_role) @user_params = user_params @current_user_role = current_user_role @permitted_params_by_role = permitted_params_by_role end def sanitise sanitised_params end ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/volatile_lock.rb
Ruby
mit
97
main
1,056
class VolatileLock class FailedToSetExpiration < StandardError; end module DSL def with_lock(key) # lock for next 10.minutes if VolatileLock.new(key).obtained? yield else puts "Skipping task on #{Socket.gethostname}, couldn't obtain lock: #{key}" end end end # e...
github
alphagov/signon
https://github.com/alphagov/signon
lib/expired_not_signed_in_user_deleter.rb
Ruby
mit
97
main
427
class ExpiredNotSignedInUserDeleter def delete User.expired_never_signed_in.find_each do |user| EventLog.record_event( user, EventLog::ACCOUNT_DELETED, trailing_message: log_message(user), ) user.destroy! end end private def log_message(user) "#{user.email}...
github
alphagov/signon
https://github.com/alphagov/signon
lib/sso_push_credential.rb
Ruby
mit
97
main
826
class SSOPushCredential PERMISSIONS = %w[user_update_permission].freeze USER_NAME = "Signon API Client (permission and suspension updater)".freeze USER_EMAIL = "signon+permissions@alphagov.co.uk".freeze class << self def credentials(application) return if application.retired? user.grant_applic...
github
alphagov/signon
https://github.com/alphagov/signon
lib/inactive_users_suspender.rb
Ruby
mit
97
main
770
class InactiveUsersSuspender def suspend inactive_users = User.not_recently_unsuspended.last_signed_in_before(User::SUSPENSION_THRESHOLD_PERIOD.ago).each do |user| user.suspended_at = Time.current user.reason_for_suspension = reason user.save!(validate: false) user.revoke_all_authorisatio...
github
alphagov/signon
https://github.com/alphagov/signon
lib/inactive_users_suspension_reminder_mailing_list.rb
Ruby
mit
97
main
674
class InactiveUsersSuspensionReminderMailingList DAYS_TO_SUSPENSION = [14, 7, 3, 1].freeze def initialize(suspension_threshold_period) @suspension_threshold_period = suspension_threshold_period end def generate suspension_threshold_exceeded = @suspension_threshold_period + 1.day suspension_remind...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles.rb
Ruby
mit
97
main
528
module Roles def self.all [ Roles::Admin, Roles::Normal, Roles::OrganisationAdmin, Roles::Superadmin, Roles::SuperOrganisationAdmin, ].sort_by(&:level) end def self.find(role_name) all.find { |role| role.name == role_name } end all.each do |klass| define_method(...
github
alphagov/signon
https://github.com/alphagov/signon
lib/sso_push_error.rb
Ruby
mit
97
main
309
class SSOPushError < StandardError def initialize(application, details = {}) message = "Error pushing to #{application.name}" message += ", got response #{details[:response_code]}" if details[:response_code] message += ". #{details[:message]}" if details[:message] super(message) end end
github
alphagov/signon
https://github.com/alphagov/signon
lib/user_permission_migrator.rb
Ruby
mit
97
main
884
class UserPermissionMigrator def self.migrate(source:, target:) source_app = Doorkeeper::Application.find_by!(name: source) target_app = Doorkeeper::Application.find_by!(name: target) source_app_supported_permissions = source_app.supported_permissions target_app_supported_permissions = target_app.supp...
github
alphagov/signon
https://github.com/alphagov/signon
lib/organisations_fetcher.rb
Ruby
mit
97
main
2,785
require "gds_api/organisations" # Whitehall is the canonical source for organisations, so Signon needs to keep # its organisations up-to-date in order to provide accurate information on user # membership of organisations. class OrganisationsFetcher def call organisation_relationships = organisations.each_with_ob...
github
alphagov/signon
https://github.com/alphagov/signon
lib/supported_permission_parameter_filter.rb
Ruby
mit
97
main
1,313
class SupportedPermissionParameterFilter attr_reader :current_user, :user, :param_set def initialize(current_user, user, param_set) @current_user = current_user @user = user @param_set = param_set end def filtered_supported_permission_ids # any permissions not in "attempting_to_add" should be ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/expired_oauth_access_records_deleter.rb
Ruby
mit
97
main
1,071
class ExpiredOauthAccessRecordsDeleter CLASSES = { access_grant: Doorkeeper::AccessGrant, access_token: Doorkeeper::AccessToken, }.freeze EVENTS = { access_grant: EventLog::ACCESS_GRANTS_DELETED, access_token: EventLog::ACCESS_TOKENS_DELETED, }.freeze def initialize(record_type:) @record_...
github
alphagov/signon
https://github.com/alphagov/signon
lib/exception_handler.rb
Ruby
mit
97
main
847
require "sso_push_error" module ExceptionHandler def with_exception_handling yield rescue URI::InvalidURIError raise SSOPushError.new(@application, message: "Invalid URL for application.") rescue GdsApi::EndpointNotFound, SocketError raise SSOPushError.new(@application, message: "Couldn't find the ap...
github
alphagov/signon
https://github.com/alphagov/signon
lib/code_verifier.rb
Ruby
mit
97
main
377
class CodeVerifier MAX_2SV_DRIFT_SECONDS = 30 attr_reader :code, :otp_secret_key def initialize(code, otp_secret_key) @code = code @otp_secret_key = otp_secret_key end def verify totp = ROTP::TOTP.new(otp_secret_key) totp.verify(clean_code, drift_behind: MAX_2SV_DRIFT_SECONDS) end priva...
github
alphagov/signon
https://github.com/alphagov/signon
lib/sso_push_client.rb
Ruby
mit
97
main
619
require "gds_api/base" require "exception_handler" class SSOPushClient < GdsApi::Base include ExceptionHandler def initialize(application) @application = application super(application.url_without_path, bearer_token: SSOPushCredential.credentials(application)) end def update_user(uid, user) with_e...
github
alphagov/signon
https://github.com/alphagov/signon
lib/signin_permission_granter.rb
Ruby
mit
97
main
458
class SigninPermissionGranter def self.call(users:, application:) users.each do |user| puts "Checking user ##{user.id}: #{user.name}" next if user.has_access_to?(application) puts "-- Adding signin permission for #{application.name}" user.grant_application_signin_permission(application) ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/organisation_mappings/zendesk_to_signon.rb
Ruby
mit
97
main
2,937
module OrganisationMappings class ZendeskToSignon def self.apply OrganisationMappings.domain_names_to_organisations.each do |domain_names, organisation_name| organisation = Organisation.find_by(name: organisation_name) if organisation User .where(organisation_id: nil) ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/applications.rake
Ruby
mit
97
main
1,564
namespace :applications do desc "Creates an application(OAuth client)" task create: :environment do # Create client app a = Doorkeeper::Application.create!( name: ENV["name"], redirect_uri: ENV["redirect_uri"], description: ENV["description"], home_uri: ENV["home_uri"], api_onl...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/data_hygiene.rake
Ruby
mit
97
main
1,149
namespace :data_hygiene do desc "Bulk update the organisations associated with users." task :bulk_update_organisation, %i[csv_filename] => :environment do |_, args| unless DataHygiene::BulkOrganisationUpdater.call(args[:csv_filename]) abort "bulk updating organisations encountered errors" end end ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/organisation_mappings.rake
Ruby
mit
97
main
498
namespace :organisation_mappings do desc "Apply organisation mappings from Zendesk to signon users" task zendesk_to_signon: :environment do users_without_organisations = User.where(organisation_id: nil).count OrganisationMappings::ZendeskToSignon.apply puts "#{users_without_organisations - User.where(...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/sync_kubernetes_secrets.rake
Ruby
mit
97
main
1,054
namespace :kubernetes do desc "Synchronise OAuth Token secrets in Kubernetes" task sync_token_secrets: :environment do client = Kubernetes::Client.new api_users = ApiUser.where(suspended_at: nil) api_users.each do |api_user| api_user.authorisations.not_revoked.ordered_by_expires_at.group_by(&:ap...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/event_log.rake
Ruby
mit
97
main
298
require "csv" namespace :event_log do desc "Delete all events in the event log older than 2 years" task delete_logs_older_than_two_years: :environment do delete_count = EventLog.where("created_at < ?", 2.years.ago).delete_all puts "#{delete_count} event log entries deleted" end end
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/organisations.rake
Ruby
mit
97
main
219
namespace :organisations do desc "Fetch organisations" task fetch: :environment do include VolatileLock::DSL with_lock("signon:organisations:fetch") do OrganisationsFetcher.new.call end end end
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/users.rake
Ruby
mit
97
main
5,789
require "date" namespace :users do desc "Remind users that their account will get suspended" task send_suspension_reminders: :environment do include VolatileLock::DSL with_lock("signon:users:send_suspension_reminders") do suspension_reminder_mailing_list = InactiveUsersSuspensionReminderMailingList....
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/oauth_access_records.rake
Ruby
mit
97
main
531
namespace :oauth_access_grants do desc "Delete expired OAuth access grants" task delete_expired: "oauth_access_records:delete_expired" end namespace :oauth_access_records do desc "Delete expired OAuth access grants and tokens" task delete_expired: :environment do %i[access_grant access_token].each do |reco...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/access_tokens.rake
Ruby
mit
97
main
1,033
namespace :access_tokens do desc "Renew expiring access tokens for internal applications" task renew_expiring_internal_tokens: :environment do expiring_tokens = Doorkeeper::AccessToken.expires_before(1.month.from_now) expiring_tokens.each do |token| user = User.find_by(id: token.resource_owner_id) ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/tasks/permissions.rake
Ruby
mit
97
main
9,021
namespace :permissions do desc "Update anyone with a managing editor permission and a normal role to an org admin role" task promote_managing_editors_to_org_admins: :environment do managing_editor_permissions = SupportedPermission.where("name REGEXP ?", "managing.*editor").pluck(:id) user_application_permis...
github
alphagov/signon
https://github.com/alphagov/signon
lib/data_hygiene/bulk_organisation_updater.rb
Ruby
mit
97
main
1,900
require "csv" module DataHygiene class BulkOrganisationUpdater def initialize(filename, logger: Rails.logger) @filename = filename @logger = logger end def call error_encountered = false CSV.foreach(filename, **CSV_OPTIONS) do |row| error_encountered = true unless proces...
github
alphagov/signon
https://github.com/alphagov/signon
lib/devise/hooks/two_step_verification.rb
Ruby
mit
97
main
560
module Devise::Hooks::TwoStepVerification Warden::Manager.after_authentication do |user, auth, _options| if user.need_two_step_verification? cookie = auth.env["action_dispatch.cookies"].signed["remember_2sv_session"] valid = cookie && cookie["user_id"] == user.id && cookie["valid_until...
github
alphagov/signon
https://github.com/alphagov/signon
lib/devise/models/suspendable.rb
Ruby
mit
97
main
1,796
module Devise module Models module Suspendable extend ActiveSupport::Concern included do # active scope is returning all users, including those # where suspend_at = nil... # using User.not_suspended for now # TODO: work out why this scope is not working # ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/devise/models/password_archivable.rb
Ruby
mit
97
main
2,929
module Devise # How many passwords to keep in archive mattr_accessor :password_archiving_count self.password_archiving_count = 5 # Deny old password (true, false, count) mattr_accessor :deny_old_passwords self.deny_old_passwords = true module Models # PasswordArchivable module PasswordArchivable...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/super_organisation_admin.rb
Ruby
mit
97
main
592
module Roles class SuperOrganisationAdmin < Base def self.permitted_user_params [ :uid, :name, :email, :password, :password_confirmation, :unconfirmed_email, :confirmation_token, :require_2sv, { supported_permission_ids: [] }, ] ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/superadmin.rb
Ruby
mit
97
main
571
module Roles class Superadmin < Base def self.permitted_user_params [ :uid, :name, :email, :password, :password_confirmation, :organisation_id, :unconfirmed_email, :confirmation_token, :role, :require_2sv, { supported_pe...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/normal.rb
Ruby
mit
97
main
405
module Roles class Normal < Base def self.permitted_user_params %i[uid name email password password_confirmation] end def self.name "normal" end def self.level 4 end def self.manageable_roles [] end def self.manageable_organisations_for(_) Organisa...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/admin.rb
Ruby
mit
97
main
546
module Roles class Admin < Base def self.permitted_user_params [ :uid, :name, :email, :password, :password_confirmation, :organisation_id, :unconfirmed_email, :confirmation_token, :require_2sv, { supported_permission_ids: [] }, ...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/organisation_admin.rb
Ruby
mit
97
main
573
module Roles class OrganisationAdmin < Base def self.permitted_user_params [ :uid, :name, :email, :password, :password_confirmation, :unconfirmed_email, :confirmation_token, :require_2sv, { supported_permission_ids: [] }, ] en...
github
alphagov/signon
https://github.com/alphagov/signon
lib/roles/base.rb
Ruby
mit
97
main
293
module Roles class Base def self.manageable_roles Roles.all.select { |role_class| role_class.level >= level }.reverse end def self.can_manage?(role_class) manageable_roles.include?(role_class) end def self.display_name name.humanize end end end
github
alphagov/signon
https://github.com/alphagov/signon
lib/kubernetes/client.rb
Ruby
mit
97
main
1,212
require "kubeclient" module Kubernetes class Client API_VERSION = "v1".freeze API_SERVER = "https://kubernetes.default.svc".freeze SERVICE_ACCOUNT = "/var/run/secrets/kubernetes.io/serviceaccount".freeze BEARER_TOKEN_FILE = "#{SERVICE_ACCOUNT}/token".freeze CA_FILE = "#{SERVICE_ACCOUNT}/ca.crt"....
github
alphagov/signon
https://github.com/alphagov/signon
lib/collectors/global_prometheus_collector.rb
Ruby
mit
97
main
1,271
require "prometheus_exporter" require "prometheus_exporter/server" # Load Rails models as not automatically included for Prometheus Exporter require File.expand_path("../../config/environment", __dir__) unless defined? Rails module Collectors class GlobalPrometheusCollector < PrometheusExporter::Server::TypeCollect...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config.ru
Ruby
mit
97
main
264
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true # This file is used by Rack-based servers to start the application. require_relative "config/environment" run Rails.application Rails.application.load_server
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/Gemfile
Ruby
mit
97
main
2,551
source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.3.5" # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" gem "rails", "~> 7.2.2" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem "sprockets-rails" ...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/test/controllers/calendar_controller_test.rb
Ruby
mit
97
main
442
require "test_helper" class CalendarControllerTest < ActionDispatch::IntegrationTest test "should get index" do get calendar_index_url assert_response :success end test "should get new" do get calendar_new_url assert_response :success end test "should post new" do post calendar_new_url,...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/test/controllers/auth_controller_test.rb
Ruby
mit
97
main
380
require "test_helper" class AuthControllerTest < ActionDispatch::IntegrationTest OmniAuth.config.test_mode = true test "post signin should redirect to callback" do post "/auth/microsoft_graph_auth" assert_response :redirect end test "get callback should redirect to home" do get "/auth/microsoft_g...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/environment.rb
Ruby
mit
97
main
429
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true # Load the Rails application. require_relative "application" # Load OAuth settings oauth_environment_variables = File.join(Rails.root, 'config', 'oauth_environment_variables.rb') load(oauth_environment_variables) if...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/boot.rb
Ruby
mit
97
main
311
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. require "bootsnap/setup" # Speed up boot time by caching expensive operations.
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/routes.rb
Ruby
mit
97
main
441
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true Rails.application.routes.draw do get 'calendar/index' get 'calendar/new' get 'home/index' root 'home#index' get 'auth/signout' get 'calendar', to: 'calendar#index' post 'calendar/new', to: 'calendar#cre...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/application.rb
Ruby
mit
97
main
812
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true require_relative "boot" require "rails/all" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module GraphSample cla...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/initializers/omniauth_graph.rb
Ruby
mit
97
main
359
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true require 'microsoft_graph_auth' Rails.application.config.middleware.use OmniAuth::Builder do provider :microsoft_graph_auth, ENV.fetch('AZURE_APP_ID'), ENV.fetch('AZURE_APP_SECRET'), ...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/config/environments/production.rb
Ruby
mit
97
main
3,898
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your applica...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/lib/microsoft_graph_auth.rb
Ruby
mit
97
main
1,799
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true require 'omniauth-oauth2' module OmniAuth module Strategies # Implements an OmniAuth strategy to get a Microsoft Graph # compatible token from Azure AD class MicrosoftGraphAuth < OmniAuth::Strategies::...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/app/helpers/graph_helper.rb
Ruby
mit
97
main
10,147
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true require 'httparty' # Graph API helper methods module GraphHelper GRAPH_HOST = 'https://graph.microsoft.com' def make_api_call(method, endpoint, token, headervals = nil, params = nil, payload = nil) headerva...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/app/controllers/auth_controller.rb
Ruby
mit
97
main
447
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true class AuthController < ApplicationController skip_before_action :set_user def callback # Access the authentication hash for omniauth data = request.env['omniauth.auth'] # Save the data in the sessio...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/app/controllers/calendar_controller.rb
Ruby
mit
97
main
1,413
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true # Calendar controller class CalendarController < ApplicationController include GraphHelper def index # Get the IANA identifier of the user's time zone time_zone = get_iana_from_windows(user_timezone) ...
github
microsoftgraph/msgraph-sample-rubyrailsapp
https://github.com/microsoftgraph/msgraph-sample-rubyrailsapp
graph-sample/app/controllers/application_controller.rb
Ruby
mit
97
main
2,037
# Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # frozen_string_literal: true require 'microsoft_graph_auth' require 'oauth2' class ApplicationController < ActionController::Base before_action :set_user def set_user @user_name = user_name @user_email = user_email end def sav...