Class: ADAL::WSTrustRequest

Inherits:
Object
  • Object
show all
Includes:
Logging, Util, XmlNamespaces
Defined in:
lib/adal/wstrust_request.rb

Overview

A request to a WS-Trust endpoint of an ADFS server. Used to obtain a SAML token that can be exchanged for an access token at a token endpoint.

Constant Summary collapse

DEFAULT_APPLIES_TO =
'urn:federation:MicrosoftOnline'
ACTION_TO_RST_TEMPLATE =
{
  WSTRUST_13 =>
    File.expand_path('../templates/rst.13.xml.erb', __FILE__),
  WSTRUST_2005 =>
    File.expand_path('../templates/rst.2005.xml.erb', __FILE__)
}

Constants included from XmlNamespaces

XmlNamespaces::ACTION_TO_NAMESPACE, XmlNamespaces::BINDING_TO_ACTION, XmlNamespaces::NAMESPACES, XmlNamespaces::NAMESPACES_13, XmlNamespaces::NAMESPACES_2005, XmlNamespaces::WSTRUST_13, XmlNamespaces::WSTRUST_2005

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::DEFAULT_LOG_OUTPUT

Instance Method Summary collapse

Methods included from Util

#fail_if_arguments_nil, #http, #string_hash

Methods included from Logging

#logger

Constructor Details

#initialize(endpoint, action = WSTRUST_13, applies_to = DEFAULT_APPLIES_TO) ⇒ WSTrustRequest

Constructs a new WSTrustRequest.

Parameters:

  • String|URI

    endpoint

  • String

    action

  • String

    applies_to



54
55
56
57
58
59
60
# File 'lib/adal/wstrust_request.rb', line 54

def initialize(
  endpoint, action = WSTRUST_13, applies_to = DEFAULT_APPLIES_TO)
  @applies_to = applies_to
  @endpoint = URI.parse(endpoint.to_s)
  @action = action
  @render = ERB.new(File.read(ACTION_TO_RST_TEMPLATE[action]))
end

Instance Method Details

#execute(username, password) ⇒ Object

Performs a WS-Trust RequestSecurityToken request with a username and password to obtain a federated token.

Parameters:

  • String

    username

  • String

    password

Returns:

  • WSTrustResponse



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/adal/wstrust_request.rb', line 69

def execute(username, password)
  logger.verbose("Making a WSTrust request with action #{@action}.")
  request = Net::HTTP::Get.new(@endpoint.path)
  add_headers(request)
  request.body = rst(username, password)
  response = http(@endpoint).request(request)
  if response.code == '200'
    WSTrustResponse.parse(response.body)
  else
    fail WSTrustResponse::WSTrustError, "Failed request: code #{response.code}."
  end
end