Module: FeedTokenHelper

Included in:
UserSettings::PersonalAccessTokensController
Defined in:
app/helpers/feed_token_helper.rb

Instance Method Summary collapse

Instance Method Details

#generate_feed_token(type) ⇒ Object



4
5
6
# File 'app/helpers/feed_token_helper.rb', line 4

def generate_feed_token(type)
  generate_feed_token_with_path(type, current_request.path)
end

#generate_feed_token_with_path(type, path) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'app/helpers/feed_token_helper.rb', line 8

def generate_feed_token_with_path(type, path)
  feed_token = current_user&.feed_token
  return unless feed_token

  final_path = path
  final_path += ".#{type}" unless path.ends_with?(".#{type}")
  digest = OpenSSL::HMAC.hexdigest("SHA256", feed_token, final_path)
  "#{::User.prefix_for_feed_token}#{digest}-#{current_user.id}"
end