Class: SelfSDK::Services::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/services/auth.rb

Overview

Input class to handle authentication requests on self network.

Instance Method Summary collapse

Constructor Details

#initialize(requester) ⇒ SelfSDK::Services::Authentication

Creates a new authentication service. Authentication service mainly manages authentication requests against self users wanting to authenticate on your app.

Parameters:

  • messaging (SelfSDK::Messaging)

    messaging object.

  • client (SelfSDK::Client)

    http client object.



19
20
21
# File 'lib/services/auth.rb', line 19

def initialize(requester)
  @requester = requester
end

Instance Method Details

Generates a deep link to authenticate with self app.

Parameters:

  • callback (String)

    the callback identifier you’ll be redirected to if the app is not installed.

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :selfid (String)

    the user selfid you want to authenticate.

  • :cid (String)

    The unique identifier of the authentication request.

Returns:

  • (String, String)

    conversation id or encoded body.



77
78
79
80
81
82
# File 'lib/services/auth.rb', line 77

def generate_deep_link(callback, opts = {})
  opts[:auth] = true
  facts = opts.fetch(:facts, [])

  @requester.generate_deep_link(facts, callback, opts)
end

#generate_qr(opts = {}) ⇒ String

Generates a QR code so users can authenticate to your app.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :selfid (String)

    the user selfid you want to authenticate.

  • :cid (String)

    The unique identifier of the authentication request.

Returns:

  • (String, String)

    conversation id or encoded body.



63
64
65
66
67
68
# File 'lib/services/auth.rb', line 63

def generate_qr(opts = {})
  opts[:auth] = true
  facts = opts.fetch(:facts, [])

  @requester.generate_qr(facts, opts)
end

#request(selfid, opts = {}) {|request| ... } ⇒ String #request(selfid, opts = {}) ⇒ String

Sends an authentication request to the specified selfid. An authentication requests allows your users to authenticate on your app using a secure self app.

Overloads:

  • #request(selfid, opts = {}) {|request| ... } ⇒ String

    Returns conversation id or encoded body.

    Parameters:

    • selfid (String)

      the receiver of the authentication request.

    • opts (Hash) (defaults to: {})

      the options to authenticate.

    Options Hash (opts):

    • :cid (String)

      The unique identifier of the authentication request.

    • :facts (Array)

      array of facts to be requested

    Yields:

    • (request)

      Invokes the block with an authentication response for each result.

    Returns:

    • (String, String)

      conversation id or encoded body.

  • #request(selfid, opts = {}) ⇒ String

    Returns conversation id or encoded body.

    Parameters:

    • selfid (String)

      the receiver of the authentication request.

    • opts (Hash) (defaults to: {})

      the options to authenticate.

    Options Hash (opts):

    • :cid (String)

      The unique identifier of the authentication request.

    • :facts (Array)

      array of facts to be requested

    Returns:

    • (String, String)

      conversation id or encoded body.



42
43
44
45
46
47
# File 'lib/services/auth.rb', line 42

def request(selfid, opts = {}, &block)
  opts[:auth] = true
  facts = opts.fetch(:facts, [])

  @requester.request(selfid, facts, opts, &block)
end

#subscribe(&block) ⇒ Object

Adds an observer for a fact response Whenever you receive a fact response registered observers will receive a notification.

@yield [request] Invokes the block with a fact response message.


53
54
55
# File 'lib/services/auth.rb', line 53

def subscribe(&block)
  @requester.subscribe(true, &block)
end