Class: BrowserID::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/browserid-provider/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Identity

Options ==

:key_path where to store the OpenSSL private key



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/browserid-provider/identity.rb', line 10

def initialize(options = {})
  @config = BrowserID::Config.new(options)

  keypath = @config.private_key_path

  if File.exists?(keypath)
    File.open(keypath) {|f| @privkey = OpenSSL::PKey::RSA.new(f.read) }
    @pubkey = @privkey.public_key
  else
    require 'fileutils'
    FileUtils.mkdir_p keypath.sub(File.basename(keypath),'')
    @privkey = OpenSSL::PKey::RSA.new(2048)
    @pubkey = @privkey.public_key
    File.open(keypath, "w") {|f| f.write(@privkey) }
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/browserid-provider/identity.rb', line 6

def config
  @config
end

Instance Method Details

#private_keyObject



31
32
33
# File 'lib/browserid-provider/identity.rb', line 31

def private_key
  @privkey
end

#public_keyObject



27
28
29
# File 'lib/browserid-provider/identity.rb', line 27

def public_key
  @pubkey
end

#to_jsonObject

Return BrowserID Identity JSON



36
37
38
39
40
41
42
# File 'lib/browserid-provider/identity.rb', line 36

def to_json
  {
    "public-key" => { "algorithm"=> "RS", "n" => public_key.n.to_s, "e" => public_key.e.to_s },
    "authentication" => @config.,
    "provisioning" => @config.provision_path
  }.to_json
end