-
Notifications
You must be signed in to change notification settings - Fork 166
LG-6204/LG-6220: capture user pii in a signed JWT and pass to frontend #6282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
881c840
d506b2b
5f6f53e
deb32c7
020bb43
b9b02e7
32854ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,10 @@ def app_data | |
| base_path: idv_app_root_path, | ||
| app_name: APP_NAME, | ||
| completion_url: completion_url, | ||
| initial_values: { 'personalKey' => personal_key }, | ||
| initial_values: { | ||
| 'personalKey' => personal_key, | ||
|
||
| 'userBundleToken' => user_bundle_token, | ||
| }, | ||
| enabled_step_names: IdentityConfig.store.idv_api_enabled_steps, | ||
| store_key: user_session[:idv_api_store_key], | ||
| } | ||
|
|
@@ -51,4 +54,11 @@ def completion_url | |
| after_sign_in_path_for(current_user) | ||
| end | ||
| end | ||
|
|
||
| def user_bundle_token | ||
| Idv::UserBundleTokenizer.new( | ||
| user: current_user, | ||
| idv_session: idv_session, | ||
| ).token | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,11 @@ interface AppRootValues { | |||||||||||||||||||||||
| * Base64-encoded encryption key for secret session store. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| storeKey: string; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Signed JWT containing user data. | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| userBundleToken: string; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| interface AppRootElement extends HTMLElement { | ||||||||||||||||||||||||
|
|
@@ -51,6 +56,15 @@ const storeKey = s2ab(atob(storeKeyBase64)); | |||||||||||||||||||||||
| const initialValues = JSON.parse(initialValuesJSON); | ||||||||||||||||||||||||
| const enabledStepNames = JSON.parse(enabledStepNamesJSON) as string[]; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const camelCase = (string: string) => | ||||||||||||||||||||||||
| string.replace(/[^a-z]([a-z])/gi, (_match, nextLetter) => nextLetter.toUpperCase()); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const jwtData = JSON.parse(atob(initialValues.userBundleToken.split('.')[1])); | ||||||||||||||||||||||||
| const pii = Object.fromEntries( | ||||||||||||||||||||||||
| Object.entries(jwtData.pii).map(([key, value]) => [camelCase(key), value]), | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| const camelCase = (string: string) => | |
| string.replace(/[^a-z]([a-z])/gi, (_match, nextLetter) => nextLetter.toUpperCase()); | |
| const jwtData = JSON.parse(atob(initialValues.userBundleToken.split('.')[1])); | |
| const pii = Object.fromEntries( | |
| Object.entries(jwtData.pii).map(([key, value]) => [camelCase(key), value]), | |
| ); | |
| import { mapKeys, camelCase } from 'lodash-es'; | |
| const jwtData = JSON.parse(atob(initialValues.userBundleToken.split('.')[1])); | |
| const pii = mapKeys(jwtData.pii, camelCase); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| module Idv | ||
| class UserBundleTokenizer | ||
| def initialize(user:, idv_session:) | ||
| @user = user | ||
| @idv_session = idv_session | ||
| end | ||
|
|
||
| def token | ||
| JWT.encode( | ||
| { | ||
| # for now, load whatever pii is saved in the session | ||
| pii: idv_session.applicant, | ||
| metadata: metadata, | ||
| }, | ||
| private_key, | ||
| 'RS256', | ||
| sub: user.uuid, | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :user, :idv_session | ||
|
|
||
| def private_key | ||
| OpenSSL::PKey::RSA.new(Base64.strict_decode64(IdentityConfig.store.idv_private_key)) | ||
| end | ||
|
|
||
| def metadata | ||
| # populate with anything from the session we'll need later on | ||
| data = {} | ||
|
|
||
| data[:address_verification_mechanism] = idv_session.address_verification_mechanism | ||
| data[:user_phone_confirmation] = idv_session.user_phone_confirmation | ||
| data[:vendor_phone_confirmation] = idv_session.vendor_phone_confirmation | ||
|
|
||
| data | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Idv::UserBundleTokenizer do | ||
| let(:public_key) do | ||
| OpenSSL::PKey::RSA.new(Base64.strict_decode64(IdentityConfig.store.idv_public_key)) | ||
| end | ||
| let(:user) { create(:user) } | ||
| let(:sp) { create(:service_provider) } | ||
| let(:user_session) do | ||
| { | ||
| idv: { | ||
| applicant: { | ||
| 'first_name' => 'Ada', | ||
| 'last_name' => 'Lovelace', | ||
| 'ssn' => '900900900', | ||
| 'phone' => '+1 410-555-1212', | ||
| }, | ||
| address_verification_mechanism: 'phone', | ||
| user_phone_confirmation: true, | ||
| vendor_phone_confirmation: true, | ||
| }, | ||
| } | ||
| end | ||
| let(:idv_session) do | ||
| Idv::Session.new(user_session: user_session, current_user: user, service_provider: sp) | ||
| end | ||
| subject do | ||
| Idv::UserBundleTokenizer.new(user: user, idv_session: idv_session) | ||
| end | ||
|
|
||
| context 'when initialized with data' do | ||
| it 'encodes a signed JWT' do | ||
| token = subject.token | ||
| decorator = Api::UserBundleDecorator.new(user_bundle: token, public_key: public_key) | ||
|
|
||
| expect(decorator.pii).to eq user_session[:idv][:applicant] | ||
| end | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.