Sha256: 26cda77ab15886c3081998736585cad757f8db5685d1fc2c55c1698b94a1519b

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

require 'nokogiri'
require 'omniauth-http-basic'

module OmniAuth
  module Strategies
    class Broadworks < OmniAuth::Strategies::HttpBasic

      option :title,    "Broadworks Login"

      uid { content_of('Profile/details/userId') }

      credentials { {:username => username, :password => password, :expires_days => content_of('Profile/passwordExpiresDays')} }

      info do
        { :name => "#{content_of('Profile/details/firstName')} #{content_of('Profile/details/lastName')}",
          :nickname => request['username'] }
      end

      extra do
        { :number => content_of('Profile/details/number'),
          :extension => content_of('Profile/details/extension'),
          :group     => content_of('Profile/details/groupId'),
          :provider  => content_of('Profile/details/serviceProvider') }
      end

      protected

        def api_uri
          "#{options.endpoint}/user/#{username}/profile"
        end

        def username
          "#{request['username']}@#{options.domain}" if request['username']
        end

        def xml_response
          @xml_response ||= Nokogiri.XML(authentication_response.body)
        end

        def content_of(path)
          xml_response.search(path).first.content
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-broadworks-1.0.0 lib/omniauth/strategies/broadworks.rb