Class: Gitlab::Auth::Otp::Strategies::FortiAuthenticator

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/auth/otp/strategies/forti_authenticator.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Gitlab::Auth::Otp::Strategies::Base

Instance Method Details

#validate(otp_code) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/auth/otp/strategies/forti_authenticator.rb', line 8

def validate(otp_code)
  body = { username: user.username,
           token_code: otp_code }

  response = Gitlab::HTTP.post(
    auth_url,
    headers: { 'Content-Type': 'application/json' },
    body: body.to_json,
    basic_auth: api_credentials)

  # Successful authentication results in HTTP 200: OK
  # https://docs.fortinet.com/document/fortiauthenticator/6.2.0/rest-api-solution-guide/704555/authentication-auth
  response.ok? ? success : error_from_response(response)
rescue StandardError => ex
  Gitlab::AppLogger.error(ex)
  error(ex.message)
end