如何编写使用Ruby萨翁SOAP验证头 [英] How to write SOAP Authentication header with Ruby Savon

查看:228
本文介绍了如何编写使用Ruby萨翁SOAP验证头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为第一次基于SOAP的API调用,我必须从文档以下信息:


  

在你的客户,构建你的授权头如下:


  
  

1串连的用户名和密码,例如:
  EXAMPLEUSERNAME:ExamplePassword


  
  

2恩code在基地64,例如字符串:
  RXhhbXBsZVVzZXJOYW1lOkV4YW1wbGVQYXNzd29yZA ==


  
  

3在code,与价值基本进入Authorization头。


  
  

例Web服务的头有连接codeD的用户名和密码


  
  

https://api.five9.com/wsadmin/AdminWebService HTTP / 1.1


  
  

接受编码:gzip,紧缩


  
  

内容类型:文本/ XML的,字符集= UTF-8


  
  

的SOAPAction:


  
  

授权:基本RXhhbXBsZVVzZXJOYW1lOkV4YW1wbGVQYXNzd29yZA ==


我现在用的是萨翁宝石,使我的电话。我将如何,使用Ruby 1.9.3和萨翁宝石,鉴定给出了上述信息的API调用 api_call

这是我使用的设置是什么WSDL,或客户端

 客户端= Savon.client(WSDL:https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=luigi@apitest.com)


解决方案

您需要在您的消息的SOAP消息头的鉴别凭证。
萨翁提供:SOAP_HEADER符号它

您的例子可以是这样的:

 要求莎翁情史
要求的SecureRandom境界= Base64.strict_en code64(EXAMPLEUSERNAME:ExamplePassword)
客户端= Savon.client(
    WSDL:https://api.five9.com/wsadmin/v2/AdminWebService?wsdl
    SOAP_HEADER:{'授权:'=> 基本#{境界}},
    日志:真实,
    LOG_LEVEL:调试,
    pretty_print_xml:真

我无法测试这个例子,因为我缺乏用户凭据,但它通过了红宝石-c。

I am making calls to a SOAP based API for the first time, and I have the following info from the documentation:

In your client, construct your authorization header as follows:

1 Concatenate the user name and password, for example: ExampleUsername:ExamplePassword

2 Encode the string in base 64, for example: RXhhbXBsZVVzZXJOYW1lOkV4YW1wbGVQYXNzd29yZA==

3 In your code, enter the Authorization header with the value Basic .

Example Web Services header with encoded user name and password

POST https://api.five9.com/wsadmin/AdminWebService HTTP/1.1

Accept-Encoding: gzip,deflate

Content-Type: text/xml;charset=UTF-8

SOAPAction: ""

Authorization: Basic RXhhbXBsZVVzZXJOYW1lOkV4YW1wbGVQYXNzd29yZA==

I am using the Savon gem to make my call. How would I, using Ruby 1.9.3 and the Savon gem, authenticate an API call api_call given the above information?

This is what I am using to setup the WSDL, or client.

client = Savon.client(wsdl: "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=luigi@apitest.com")

解决方案

You need to include the authentification credentials in the SOAP header of your message. Savon offers the :soap_header symbol for it.

Your example could look like this:

require 'savon'
require 'securerandom'

realm = Base64.strict_encode64("ExampleUsername:ExamplePassword")
client = Savon.client(
    wsdl: "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl",
    soap_header: { 'Authorization:' => "Basic #{realm}"},
    log: true,
    log_level: debug,
    pretty_print_xml: true
)

I couldn't test it this example because I lack the user credentials, but it passed "ruby -c".

这篇关于如何编写使用Ruby萨翁SOAP验证头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆