File: ui.rb

package info (click to toggle)
ruby-openid 2.5.0debian-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,980 kB
  • ctags: 2,219
  • sloc: ruby: 16,737; xml: 219; sh: 24; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,366 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# An implementation of the OpenID User Interface Extension 1.0 - DRAFT 0.5
# see: http://svn.openid.net/repos/specifications/user_interface/1.0/trunk/openid-user-interface-extension-1_0.html

require 'openid/extension'

module OpenID

  module UI
    NS_URI = "http://specs.openid.net/extensions/ui/1.0"

    class Request < Extension
      attr_accessor :lang, :icon, :mode, :ns_alias, :ns_uri
      def initialize(mode = nil, icon = nil, lang = nil)
        @ns_alias = 'ui'
        @ns_uri = NS_URI
        @lang = lang
        @icon = icon
        @mode = mode
      end

      def get_extension_args
        ns_args = {}
        ns_args['lang'] = @lang if @lang
        ns_args['icon'] = @icon if @icon
        ns_args['mode'] = @mode if @mode
        return ns_args
      end

      # Instantiate a Request object from the arguments in a
      # checkid_* OpenID message
      # return nil if the extension was not requested.
      def self.from_openid_request(oid_req)
        ui_req = new
        args = oid_req.message.get_args(NS_URI)
        if args == {}
          return nil
        end
        ui_req.parse_extension_args(args)
        return ui_req
      end

      # Set UI extension parameters
      def parse_extension_args(args)
        @lang = args["lang"]
        @icon = args["icon"]
        @mode = args["mode"]
      end

    end

  end

end