Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/forest_admin_agent/forest_admin_agent.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ admin work on any Ruby application."
spec.add_dependency "filecache", "~> 1.0"
spec.add_dependency "ipaddress", "~> 0.8.3"
spec.add_dependency "jsonapi-serializers", "~> 1.0"
spec.add_dependency "jwt", "~> 2.7"
spec.add_dependency "jwt", "~> 3.1"
spec.add_dependency "ld-eventsource", "~> 2.2"
spec.add_dependency "mono_logger", "~> 1.1"
spec.add_dependency "openid_connect", "~> 2.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'date'
require 'active_support'
require 'active_support/core_ext/numeric/time'
require 'jwt'

module ForestAdminAgent
Expand All @@ -15,19 +16,21 @@ def id
end

def expiration_in_seconds
(DateTime.now + (1 / 24.0)).to_time.to_i
Time.now.to_i + 1.hour
end

def make_jwt
attributes = @data['attributes']

user = {
id: id,
email: attributes['email'],
first_name: attributes['first_name'],
last_name: attributes['last_name'],
team: attributes['teams'][0],
role: attributes['role'],
tags: attributes['tags'],
rendering_id: @rendering_id,
rendering_id: @rendering_id.to_s,
exp: expiration_in_seconds,
permission_level: attributes['permission_level']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module OAuth2
'first_name' => 'john',
'last_name' => 'doe',
'teams' => ['team'],
'role' => 'role',
'tags' => ['tag'],
'permission_level' => 'permission_level'
}
Expand All @@ -25,7 +26,7 @@ module OAuth2
context 'when creating a new ForestResourceOwner' do
it 'initializes the forest resource owner' do
expect(forest_resource_owner.id).to eq 'id'
expect(forest_resource_owner.expiration_in_seconds).to eq (DateTime.now + (1 / 24.0)).to_time.to_i
expect(forest_resource_owner.expiration_in_seconds).to eq Time.now.to_i + 1.hour
end

it 'makes a jwt' do
Expand All @@ -37,9 +38,10 @@ module OAuth2
'first_name' => 'john',
'last_name' => 'doe',
'team' => 'team',
'role' => 'role',
'tags' => ['tag'],
'rendering_id' => 10,
'exp' => forest_resource_owner.expiration_in_seconds,
'rendering_id' => '10',
'exp' => forest_resource_owner.expiration_in_seconds.to_s,
'permission_level' => 'permission_level'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Security
'permission_level' => 'admin'
}
end
let(:token) { JWT.encode :user, ForestAdminAgent::Facades::Container.cache(:auth_secret), 'HS256' }
let(:token) { JWT.encode user, ForestAdminAgent::Facades::Container.cache(:auth_secret), 'HS256' }
let(:auth_manager) { instance_double(ForestAdminAgent::Auth::AuthManager) }

before do
Expand Down
Loading