Sha256: 2023ef55e6be72cc3928f49abbdca59243036f42721fad6d68f3405ae7e5cede
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require 'descope' @logger = Logger.new($stdout) @project_id = ENV['DESCOPE_PROJECT_ID'] @management_key = ENV['DESCOPE_MANAGEMENT_KEY'] @logger.info("Initializing Descope API with project_id: #{@project_id} and base_uri: #{@base_uri}") @client = Descope::Client.new({ project_id: @project_id, management_key: @management_key }) access_key = nil begin @logger.info('Going to login by using access key ...') if access_key.nil? print "Insert access key here\n" access_key = gets.chomp end begin jwt_response = @client.exchange_access_key(access_key) @logger.info('exchange access key successfully') @logger.info("jwt_response: #{jwt_response}") permission_name = 'TestPermission' permission_presented = @client.validate_permissions( jwt_response:, permissions: [permission_name] ) @logger.info("#{permission_name} presented on the jwt: [#{permission_presented}]") role_name = 'TestRole' role_presented = @client.validate_roles(jwt_response:, roles: [role_name]) @logger.info("#{role_name} presented on the jwt: [#{role_presented}]") rescue Descope::AuthException => e @logger.error("Failed to exchange access key #{e}") raise end rescue StandardError => e @logger.error("Failed to initialize DescopeClient #{e}") raise end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
descope-1.0.4 | examples/ruby/access_key_app.rb |