Module: PublishingPlatform::SSO::MockBearerToken

Defined in:
lib/publishing_platform_sso/bearer_token.rb

Class Method Summary collapse

Class Method Details

.locate(_token_string) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/publishing_platform_sso/bearer_token.rb', line 57

def self.locate(_token_string)
  dummy_api_user = PublishingPlatform::SSO.test_user || PublishingPlatform::SSO::Config.user_klass.where(email: "[email protected]").first
  if dummy_api_user.nil?
    dummy_api_user = PublishingPlatform::SSO::Config.user_klass.new
    dummy_api_user.email = "[email protected]"
    dummy_api_user.uid = rand(10_000).to_s
    dummy_api_user.name = "Dummy API user created by publishing_platform_sso"
  end

  unless dummy_api_user.has_all_permissions?(PublishingPlatform::SSO::Config.permissions_for_dummy_api_user)
    dummy_api_user.permissions = PublishingPlatform::SSO::Config.permissions_for_dummy_api_user
  end

  dummy_api_user.save!
  dummy_api_user
end