Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6228625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:25:21+00:00 2026-05-24T09:25:21+00:00

I have small application, and I will have some external applications put data to

  • 0

I have small application, and I will have some external applications put data to this service over http with rest. I already have it working but without authentication. In portal I use devise, and my question is: how to (example desired) authenticate to portal from ruby script level? What to add to following script to authenticate first? I want to protect this controller with devise and then I need authentication part to following script.

require "net/http"
require "json"

@host = "localhost"
@port = 3000
@post_ws = "/external/rd"

@req_body = {
"device" => {
  "name" => "device_json", 
  "operating_system_id" => "7", 
  "hash_string" => "jfsg3k4ovj0j02jv", 
  "user_id" => "1"
}
}.to_json

req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
req.body = @req_body
response = Net::HTTP.new(@host, @port).start {|http| http.request(req) }

Regards,
Mateusz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:25:22+00:00Added an answer on May 24, 2026 at 9:25 am

    Here is solution:

    I used token_authenticatable from devise.

    Here is one great answer how to implement it with json. I had some trouble and described them in this question. There is also answer.

    Here goes example code:

    require "net/http"
    require "json"
    
    @host = "localhost"
    @port = 3000
    @post_sign = "/users/sign_in.json"
    @post_ws = "/external/rd"
    
    @req_sign = {
    "user" => {
      "email" => "some@email.com", 
      "password" => "123456" 
    }
    }.to_json
    
    sig = Net::HTTP::Post.new(@post_sign, initheader = {'Content-Type' => 'application/json'})
    sig.body = @req_sign
    
    
    http = Net::HTTP.new(@host, @port).start
    resp1 = http.request(sig)
    puts "Response: #{resp1.code} , Message: #{resp1.message} , Body: #{resp1.body}"
    
    if resp1.code == "200" then 
      puts "logged in"
      json_resp = JSON.parse(resp1.body)
      @auth_token = json_resp['auth_token']
    
      @req_body = {
      "device" => {
        "name" => "device_json", 
        "operating_system_id" => "7", 
        "hash_string" => "jfsg3k4ovj0j02jv" 
      }, 
      "auth_token" => @auth_token 
      }.to_json
      req = Net::HTTP::Post.new(@post_ws, initheader = {'Content-Type' =>'application/json'})
      req.body = @req_body
    
      response = http.request(req)
      puts "Response: #{response.code} , Message: #{response.message} , Body: #{response.body}"
    end
    

    Regards,
    Mateusz

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small offline web that at some point my application will show
Lets say I have an old application which will try to load an external
I have developed a small C# form application which calls a web service. Everything
I´m thinking about to write an application will have to store a small amount
Im building a small application and I have some click events binded to some
I have to create a small .NET client application that will be using Exchange
I'm working on some small chat application. I want to implement smilies over there
I have a .NET 3.5 Windows Service. I'm testing with a small application that
I have a small application I am working on that at one point needs
I have a small application to convert several file formats, with a main windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.