How to do Rails Basic Authorization using RestClient?

I am trying to send a request to a REST service (API ALT 11 REST API fwiw) using a client client and continue to receive an authorization refusal. Perhaps I do not follow the documents, but also not sure that I am making the headings correctly. So far, my googling for RestClient has been fruitless. Any help would be appreciated:

the code:

@alm_url = "http://alm_url/qcbin/" @user_name = "username" @user_password = "password" authentication_url = @alm_url + "rest/is-authenticate" resource = RestClient::Resource.new authentication_url resource.head :Authorization => Base64.encode64(@user_name) + ":" + Base64.encode64(@user_password) response = resource.get #response = RestClient.get authentication_url, :authorization => @username, @user_password Rails.logger.debug response.inspect 

Based on this SO> question , I also tried the following without success:

 @alm_url = "http://alm_url/qcbin/" @user_name = "username" @user_password = "password" authentication_url = @alm_url + "rest/is-authenticate" resource = RestClient::Resource.new authentication_url, {:user => @user_name, :password => @user_password} response = resource.get #response = RestClient.get authentication_url, :authorization => @username, @user_password Rails.logger.debug response.inspect 

Documentation:

The client sends a valid Basic Authentication header for point authentication.

GET / qcbin / authentication-point / authenticate Authorization: Basic ABCDE123

The server checks the basic authentication headers, creates a new LW-SSO, and returns it as LWSSO_COOKIE_KEY.

+6
source share
1 answer

Ok ... so this will help first if I go to the correct url:

 authentication_url = @alm_url + "rest/is-authenticate" 

What to read:

 authentication_url = @alm_url + "authentication-point/authenticate" 

Secondly, it helps if I am reading documents for RestClient, and not just looking at readme. The example in Instance Information helped a lot.

Now my code is as follows:

 @alm_url = "http://alm_url/qcbin/" @user_name = "username" @user_password = "password" authentication_url = @alm_url + "authentication-point/authenticate" resource = RestClient::Resource.new(authentication_url, @user_name, @user_password) response = resource.get Rails.logger.debug response.inspect 

EDIT:

Wow, I really thought about it. I could go with:

 response = RestClient.get "http://#{@user_name}:#{@user_password}@alm_url/qcbin/authentication-point/authenticate" 
+7
source

Source: https://habr.com/ru/post/907982/


All Articles