Module: Trinidad::Sandbox::Helpers::Auth

Includes:
Sinatra::Authorization
Defined in:
lib/trinidad_sandbox_extension/app/helpers/auth.rb

Instance Method Summary collapse

Instance Method Details

#authorization_realmObject



16
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 16

def authorization_realm; "Trinidad's sandbox"; end

#authorize(user, pass) ⇒ Object



8
9
10
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 8

def authorize(user, pass)
  user == sandbox_username && pass == sandbox_password
end

#authorized?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 12

def authorized?
  sandbox_username && sandbox_password ? request.env['REMOTE_USER'] && !request.env['REMOTE_USER'].empty? : true
end

#authorized_by_token?(params) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 32

def authorized_by_token?(params)
  deploy_token.nil? || params[:deploy_token] == deploy_token
end

#basic_auth_required?(request) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 18

def basic_auth_required?(request)
  !token_required?(request)
end

#token_required(params, realm = authorization_realm) ⇒ Object



26
27
28
29
30
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 26

def token_required(params, realm = authorization_realm)
  return if authorized_by_token?(params)
  response["WWW-Authenticate"] = %(Basic realm="#{realm}")
  throw :halt, [401, "Deploy Token Required"]
end

#token_required?(request) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/trinidad_sandbox_extension/app/helpers/auth.rb', line 22

def token_required?(request)
  request.path == '/deploy'
end