Method: SelfSDK::Services::Authentication#request

Defined in:
lib/services/auth.rb

#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.

    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.

    Returns:

    • (String, String)

      conversation id or encoded body.


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/services/auth.rb', line 40

def request(selfid, opts = {}, &block)
  SelfSDK.logger.info "authenticating #{selfid}"
  rq = opts.fetch(:request, true)
  if rq
    raise "You're not permitting connections from #{selfid}" unless @messaging_service.is_permitted?(selfid)
  end

  req = SelfSDK::Messages::AuthenticationReq.new(@messaging)
  req.populate(selfid, opts)

  body = @client.jwt.prepare(req.body)
  return body unless rq
  return req.send_message if opts.fetch(:async, false)

  # when a block is given the request will always be asynchronous.
  if block_given?
    @messaging.set_observer(req, timeout: req.exp_timeout, &block)
    return req.send_message
  end

  # Otherwise the request is synchronous
  req.request
end