rails pass soap basic auth with savon

*爱你&永不变心* 提交于 2019-12-10 11:54:18

问题


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

回答1:


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



回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/28434493/rails-pass-soap-basic-auth-with-savon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!