Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_sessions_helper.rb « ci « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0296a74395c040e02647ea348bff7e210c80a2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Ci
  module UserSessionsHelper
    def generate_oauth_salt
      SecureRandom.hex(16)
    end

    def generate_oauth_hmac(salt, return_to)
      return unless return_to
      digest = OpenSSL::Digest.new('sha256')
      key = Gitlab::Application.secrets.db_key_base + salt
      OpenSSL::HMAC.hexdigest(digest, key, return_to)
    end

    def generate_oauth_state(return_to)
      return unless return_to
      salt = generate_oauth_salt
      hmac = generate_oauth_hmac(salt, return_to)
      "#{salt}:#{hmac}:#{return_to}"
    end

    def get_ouath_state_return_to(state)
      state.split(':', 3)[2] if state
    end

    def is_oauth_state_valid?(state)
      return true unless state
      salt, hmac, return_to = state.split(':', 3)
      return false unless return_to
      hmac == generate_oauth_hmac(salt, return_to)
    end
  end
end