Elmor
Elmor

Reputation: 4895

rails pass soap basic auth with savon

I'm trying to send soap request with basic authentication with savon gem
My soap server is set up with wash_out gem

class OrdersController < ApplicationController  
     soap_service namespace: 'sir:WashOut', wsse_username: SIRA[:auth][:username], wsse_password: SIRA[:auth][:password]  

....

When i make a request to soap server via savon i get an error:

    @client = Savon.client(
      wsdl:  "http://localhost:3000/orders/wsdl",
      soap_header: { 'Username' =>SIRA[:auth][:username], 'Password' => SIRA[:auth][:password] }
    )  

  @response = @client.call(:notify ).to_hash

On the last command i get an error

 Savon::SOAPFault: (Server) Missing required UsernameToken

Upvotes: 0

Views: 1633

Answers (3)

Abhi
Abhi

Reputation: 4261

For Savon 2. Basic authorization can be done as follows:

@client = Savon.client(
  wsdl: "http://localhost:3000/orders/wsdl",
  basic_auth: ["username", "password"]
)  

@response = @client.call(:notify ).to_hash

Upvotes: 0

Mukesh
Mukesh

Reputation: 931

client = Savon.client(
           wsdl: 'http://service.example.com?wsdl',
    soap_header: { 
                 "AuthenticateRequest" => 
                                {"apiKey" => "****** your api *********"}}, 
    pretty_print_xml: true)

client.operations

response = client.call(:function)

Note: "apiKey" is my prams to authenticate, your can be different

Upvotes: 3

Elmor
Elmor

Reputation: 4895

I've tried this and it works!

@client = Savon.client(
  wsdl:  "http://localhost:3000/orders/wsdl",
  wsse_auth: [SIRENA[:auth][:username], SIRENA[:auth][:password] ],
  logger: Rails.logger
)

 @response = @client.call(:notify,  ).to_hash

Upvotes: 0

Related Questions