liquidsoap source authentication

big balls of mud killer
, in 28 June 2014

Setting up source authentication in liquidsoap is pretty easy (although you may find an aforementioned hack useful, depending on what source client you may be using).

If you are using input.harbor, you can supply a function that returns true or false to be used as an authentication mechanism. Since you can call any external script in said function, its possible to connect to an external database of users to authenticate.

Just as an example, here is what I use, its a ruby script that uses the json api on my rails app running on heroku to log in. It simply returns true or false based on the result of the login.

dj_auth.rb

#!/usr/bin/env ruby

Bundler.require

require 'httparty'

username = ARGV[0]
password = ARGV[1]

opts = { body: { :user => {"login" => username, "password" => password} } }

resp = HTTParty.post("http://www.datafruits.fm/login.json", opts)
if resp["success"] == true
  puts true
else
  puts false
end

Define a function in liquid soap that calls this external script, and you can pass that function as the auth parameter to input.harbor

#auth function
def dj_auth(user,password) =
  u = get_user(user,password)
  p = get_password(user,password)
  #get the output of the script
  ret = get_process_lines("bundle exec ./dj_auth.rb #{u} #{p}")
  ret = list.hd(ret)
  #return true to let the client transmit data, or false to tell harbor to decline
  if ret == "true" then
    true
  else
    false
  end
end
live_dj = input.harbor("datafruits",port=9000,auth=dj_auth,on_disconnect=on_disconnect)

Keep in mind, in some clients there is stupidly no option to set the source password. If your djs are using said clients, you have a couple of options. You could use a silly hack I mentioned in a [previous post]/blog/icecast-source-client-hack, where you simply enter the password in the same field separated by some character and parse that. I use this method, I instruct DJs to enter their username and password separated by a semicolon if their source client has no option to set the username.

I’m currently writing a book about liquidsoap!

Modern Online Radio with Liquidsoap Book - Free Sample

Need more help with liquidsoap? Can’t get your script to work?

I wrote a book to help you learn Liquidsoap. The book covers all aspects of liquidsoap, from getting started, to making dynamic streams, audio processing, video, customizing metadata, authentication, and more. The book is available for purchase now here!

You can get a free sample chapter of my book! Just enter your email address to subscribe to my mailing list and I'll send you a free PDF sample of the book in return.