Class: IAuthU::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/iauthu/server.rb

Overview

IAuthU::Server provides a ready-to-run iTunes U (tm) authentication server. You can use

Server.build {} to easily construct and configure your authentication server:

  server = Server.build {
    run :webrick, :port => 9292
    site {
      url "https://deimos.apple.com/WebObjects/Core.woa/Browse/foo.edu"
      shared_secret "SHARED-SECRET"
    }
    auth {
      use IAuthU::Authenticator::Open
    }
  }

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



36
37
38
39
40
# File 'lib/iauthu/server.rb', line 36

def initialize
  @runner = Rack::Handler::WEBrick
  @port = 9292
  @login_page = 
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



41
42
43
# File 'lib/iauthu/server.rb', line 41

def auth
  @auth
end

#login_pageObject

Returns the value of attribute login_page.



41
42
43
# File 'lib/iauthu/server.rb', line 41

def 
  @login_page
end

#portObject

Returns the value of attribute port.



41
42
43
# File 'lib/iauthu/server.rb', line 41

def port
  @port
end

#runnerObject

Returns the value of attribute runner.



41
42
43
# File 'lib/iauthu/server.rb', line 41

def runner
  @runner
end

#siteObject

Returns the value of attribute site.



41
42
43
# File 'lib/iauthu/server.rb', line 41

def site
  @site
end

Class Method Details

.build(&block) ⇒ Object



30
31
32
33
34
# File 'lib/iauthu/server.rb', line 30

def self.build(&block)
  b = Builder.new
  b.instance_eval(&block)
  b.server
end

Instance Method Details

#call(env) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/iauthu/server.rb', line 54

def call(env)
  req = Rack::Request.new(env)
  user, pass = req.POST["username"], req.POST["password"]
  # if user && pass
  #         logged_in, result = login(user, pass)
  #       else
  #         logged_in = false
  #       end
  #       result = login_page unless logged_in
  #       res = Rack::Response.new
  #       res.write result
  #       res.finish
  unless req.POST["username"] && req.POST["password"]
    Rack::Response.new.finish do |res|
      res.write 
    end
  else
    Rack::Response.new.finish do |res|
      logged_in, result = (req.POST["username"], req.POST["password"])
      #puts result
      res.write result
    end
  end
end

#loggerObject



43
44
45
# File 'lib/iauthu/server.rb', line 43

def logger
  CONFIG[:logger]
end

#runObject



47
48
49
50
51
52
# File 'lib/iauthu/server.rb', line 47

def run
  raise "Site config is required" unless @site
  raise "Auth config is required" unless @auth
  logger.info "Running IAuthU with: #{@runner}"
  @runner.run(Rack::ShowExceptions.new(Rack::Lint.new(self)), :Port => @port)
end