Module: Genius::Auth

Defined in:
lib/genius/api/authorization.rb

Overview

Genius::Auth module is used to authenticate users with their token. It provides initialization of token instance variable.

Examples:

Genius::Auth.="yuiaYqbncErCVwItjQxFspNWUZLhGpXrPbkvgbgHSEKJRAlToamzMfdOeDB"

Class Method Summary collapse

Class Method Details

.authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}") ⇒ Boolean

Checks if the current token is authorized. Returns false on validation failure.

Parameters:

  • token (String) (defaults to: @token)

    Token to validate.

  • method_name (String) (defaults to: "#{Module.nesting[1].name}.#{__method__}")

    Method name for error messages.

Returns:

  • (Boolean)

Raises:



27
28
29
30
31
32
33
# File 'lib/genius/api/authorization.rb', line 27

def authorized?(token = @token, method_name: "#{Module.nesting[1].name}.#{__method__}")
  Errors.validate_token(token, method_name: method_name)
rescue Genius::Errors::TokenError
  false
else
  true
end

.logout!nil

Revokes the current session by setting the token to nil.

Returns:

  • (nil)


38
39
40
# File 'lib/genius/api/authorization.rb', line 38

def logout!
  @token = nil unless @token.nil?
end

.token=(token) ⇒ String Also known as: login=

Sets the authentication token after validation.

Parameters:

Returns:

Raises:



16
17
18
19
# File 'lib/genius/api/authorization.rb', line 16

def token=(token)
  Genius::Errors.validate_token(token)
  @token = token
end