module OverSIP::Modules::Callsign

Constants

VERSION

Public Class Methods

assert_callsign_identity(request) click to toggle source
# File lib/oversip-mod-callsign.rb, line 36
def assert_callsign_identity(request)
  x_callsign_token = request.header_top 'X-Callsign-Token'
  token = token_cache.get(x_callsign_token) || @client.describe_token(x_callsign_token)

  return false unless token && authorized_token?(token)

  sip_identity = token.identity.identifier

  log_system_debug "user asserted, adding P-Asserted-Identity '#{sip_identity}' for '#{request.log_id}'" if $oversip_debug
  request.set_header 'P-Asserted-Identity', '<' << sip_identity << '>'

  true
end
authorized_token?(token) click to toggle source
# File lib/oversip-mod-callsign.rb, line 50
def authorized_token?(token)
  token_client_id = token.client_id
  token_scopes = token.scope.split(' ')

  # (unauthorized) token is not associated with an authorized tenant
  return false unless config['authorized_callsign_tenants'].include? token_client_id

  # (unauthorized) token was not issued an authorized scope
  return false unless (config['authorized_callsign_scopes'] & token_scopes).size > 0

  true
end
config() click to toggle source
# File lib/oversip-mod-callsign.rb, line 17
def config
  @config ||= {}
end
configure(properties) click to toggle source
# File lib/oversip-mod-callsign.rb, line 21
def configure properties
  %w[ 
    callsign_client_id callsign_client_secret authorized_callsign_tenants authorized_callsign_scopes
  ].each do |property|
    config[property] = properties[property] || raise(OverSIP::ConfigurationError.new("Missing required Callsign configuration property: #{property}"))
  end

  @token_cache = TokenCache.new config['callsign_token_ttl']
  @client = Client.new config['callsign_client_id'], config['callsign_client_secret']
end
token_cache() click to toggle source
# File lib/oversip-mod-callsign.rb, line 32
def token_cache
  @token_cache
end