belt 0.3.14 → 0.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55308d608d7b85464c0b0861a0aa5e38ea9787ff931cf2ed9ee698d62d0bcbe8
4
- data.tar.gz: daa931d9c87236b78510a870d6a651377233d185812b8bf557a4a4afd23d6f01
3
+ metadata.gz: 491ae37769b6a21cfd1823301d425d0af0b3f1e3c19952b909febebc7f2c3b32
4
+ data.tar.gz: a2427f68a34d38be0cf3af42ac33a8d3c3d190f36505c54ef531219cd0c3fb66
5
5
  SHA512:
6
- metadata.gz: 1b1b6ac554fca615222bffd1e9089fc6e96ad089a9081b6dc83f48a7ea73477662373e57ad33d4f51aad41991fb747f67575bc68c8e8a4a9b88715f2c7af4764
7
- data.tar.gz: cf04548387af38ae1b49375ecb782fcd51878c679fbf8340f083b82c26b6900524cdf89dfc196b12d21918dd0b145e3a1de8624d7b44a118cc61eea2197aa49d
6
+ metadata.gz: 895fb4f7238141ba4752cdfc9200c44b2ef870bbc61585a436d3a9e36f39c689e8429d97ad4cf0101d92cbea06b3771864c1d31e4892dae54448a2f0e8ec138b
7
+ data.tar.gz: 4b2fee884c2f7ad9ba78bd7a46dacf75d1d5c8aa5da43d151ab7d03889aa740dd60a12a1fce5c18467f7c3bbb54aacb886a55efdcc58a997ed6367148ea37f15
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.15
4
+
5
+ ### Bug Fix
6
+
7
+ - **`belt generate auth` NEW_PASSWORD_REQUIRED challenge sent `email` even when
8
+ the user already had it**: The 0.3.14 fix always passed `{ email }` to
9
+ `completeNewPasswordChallenge`. That fixed pools where `email` was missing, but
10
+ broke the common case where the user already has `email` set (e.g. created via
11
+ `admin-create-user` with an email) — Cognito rejects that with a 400
12
+ `NotAuthorizedException: Cannot modify an already provided email`. The template
13
+ now reads the `requiredAttributes` list Cognito provides in the
14
+ `newPasswordRequired` callback and supplies `email` **only when Cognito actually
15
+ requires it**. Users with email already set complete the challenge without
16
+ re-sending it; users missing email still get it supplied. Handles both cases.
17
+
3
18
  ## 0.3.14
4
19
 
5
20
  ### Bug Fix
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.3.14'
4
+ VERSION = '0.3.15'
5
5
  end
@@ -37,41 +37,54 @@ export function signIn(username, password) {
37
37
  resolve({ success: true })
38
38
  },
39
39
  onFailure: (err) => reject(err),
40
- newPasswordRequired: () => {
41
- // Stash the user so completeNewPassword can continue the SRP session.
40
+ newPasswordRequired: (_userAttributes, requiredAttributes) => {
41
+ // Stash the user + the attributes Cognito actually requires so
42
+ // completeNewPassword can continue the SRP session and supply exactly
43
+ // what the pool asks for — no more, no less.
42
44
  pendingUser = cognitoUser
45
+ pendingRequiredAttributes = requiredAttributes || []
43
46
  resolve({ challenge: 'NEW_PASSWORD_REQUIRED' })
44
47
  }
45
48
  })
46
49
  })
47
50
  }
48
51
 
49
- // Holds the CognitoUser mid-challenge for the NEW_PASSWORD_REQUIRED flow.
52
+ // Holds the CognitoUser mid-challenge for the NEW_PASSWORD_REQUIRED flow,
53
+ // plus the list of attributes Cognito flagged as required for the challenge.
50
54
  let pendingUser = null
55
+ let pendingRequiredAttributes = []
51
56
 
52
57
  export function completeNewPassword(email, newPassword) {
53
58
  if (!pendingUser) {
54
59
  return Promise.reject(new Error('No pending password challenge. Sign in again.'))
55
60
  }
56
61
 
57
- // Pools that require `email` reject the NEW_PASSWORD_REQUIRED challenge with
58
- // "Invalid attributes given, email is missing" unless we supply it here.
59
- // Admin-created users hitting this challenge don't have email set yet, so we
60
- // pass the username (which is the email) as the required attribute.
61
- const requiredAttributes = { email }
62
+ // Only supply attributes Cognito actually asks for in this challenge.
63
+ // - If the pool requires `email` and the user doesn't have it yet, it shows
64
+ // up in requiredAttributes we send it (username is the email). Skipping
65
+ // it would fail with "Invalid attributes given, email is missing".
66
+ // - If the user already has `email` (e.g. admin-created with it), it is NOT
67
+ // in requiredAttributes → we must NOT send it, or Cognito rejects with
68
+ // "Cannot modify an already provided email".
69
+ const attributes = {}
70
+ if (pendingRequiredAttributes.includes('email')) {
71
+ attributes.email = email
72
+ }
62
73
 
63
74
  return new Promise((resolve, reject) => {
64
- pendingUser.completeNewPasswordChallenge(newPassword, requiredAttributes, {
75
+ pendingUser.completeNewPasswordChallenge(newPassword, attributes, {
65
76
  onSuccess: (session) => {
66
77
  setTokens({
67
78
  IdToken: session.getIdToken().getJwtToken(),
68
79
  RefreshToken: session.getRefreshToken().getToken()
69
80
  })
70
81
  pendingUser = null
82
+ pendingRequiredAttributes = []
71
83
  resolve({ success: true })
72
84
  },
73
85
  onFailure: (err) => {
74
86
  pendingUser = null
87
+ pendingRequiredAttributes = []
75
88
  reject(err)
76
89
  }
77
90
  })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla