Sha256: 4e093f4bb15b844a8935406404a247f75be4342d196fb54a397db0e253874e82

Contents?: true

Size: 1.25 KB

Versions: 8

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require 'jwt'
require 'adobe/campaign'

# rubocop:disable Metrics/BlockLength
namespace :adobe do
  desc 'Generate a long-life JWT for exchanging with the adobelogic server'
  task :generate_jwt do
    unless ENV['key']
      puts 'You must include a reference to the private key'
      puts 'example: rake adobe:generate_jwt key=~/certs/adobe/private.key'
      exit 1
    end

    key_path = File.expand_path(ENV['key'])
    unless File.exist? key_path
      puts 'private key does not exist!'
      exit 1
    end

    org_id = Adobe::Campaign.configuration.org_id
    tech_acct = Adobe::Campaign.configuration.tech_acct
    api_key = Adobe::Campaign.configuration.api_key
    ims_host = Adobe::Campaign.configuration.ims_host
    payload = {
      'exp' => 1.year.from_now.to_time.to_i,
      'iss' => "#{org_id}@AdobeOrg",
      'sub' => "#{tech_acct}@techacct.adobe.com",
      'aud' => "https://#{ims_host}/c/#{api_key}",
      "https://#{ims_host}/s/ent_campaign_sdk" => true
    }
    priv_key = OpenSSL::PKey::RSA.new(File.read(key_path))
    signed_jwt = JWT.encode(payload, priv_key, 'RS256')
    puts 'Your new signed JWT:'
    puts signed_jwt
    puts "It will expire: #{10.years.from_now}"
  end
end
# rubocop:enable Metrics/BlockLength

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
adobe-campaign-0.4.4 lib/tasks/adobe.rake
adobe-campaign-0.4.3 lib/tasks/adobe.rake
adobe-campaign-0.4.2 lib/tasks/adobe.rake
adobe-campaign-0.4.1 lib/tasks/adobe.rake
adobe-campaign-0.4.0 lib/tasks/adobe.rake
adobe-campaign-0.3.2 lib/tasks/adobe.rake
adobe-campaign-0.3.1 lib/tasks/adobe.rake
adobe-campaign-0.3.0 lib/tasks/adobe.rake