@@ -98,7 +98,7 @@ export class ResponseHandler {
98
98
* @param serverTokenResponse
99
99
* @param authority
100
100
*/
101
- generateAuthenticationResult ( serverTokenResponse : ServerAuthorizationTokenResponse , authority : Authority , cachedNonce ?: string , cachedState ?: string ) : AuthenticationResult {
101
+ handleServerTokenResponse ( serverTokenResponse : ServerAuthorizationTokenResponse , authority : Authority , cachedNonce ?: string , cachedState ?: string ) : AuthenticationResult {
102
102
// create an idToken object (not entity)
103
103
const idTokenObj = new IdToken ( serverTokenResponse . id_token , this . cryptoObj ) ;
104
104
@@ -116,43 +116,9 @@ export class ResponseHandler {
116
116
}
117
117
118
118
const cacheRecord = this . generateCacheRecord ( serverTokenResponse , idTokenObj , authority , requestStateObj && requestStateObj . libraryState ) ;
119
- const responseScopes = ScopeSet . fromString ( serverTokenResponse . scope ) ;
120
- this . cacheStorage . saveCacheRecord ( cacheRecord , responseScopes ) ;
121
-
122
- const authenticationResult : AuthenticationResult = {
123
- uniqueId : idTokenObj . claims . oid || idTokenObj . claims . sub ,
124
- tenantId : idTokenObj . claims . tid ,
125
- scopes : responseScopes . asArray ( ) ,
126
- account : cacheRecord . account . getAccountInfo ( ) ,
127
- idToken : idTokenObj . rawIdToken ,
128
- idTokenClaims : idTokenObj . claims ,
129
- accessToken : serverTokenResponse . access_token ,
130
- fromCache : true ,
131
- expiresOn : new Date ( cacheRecord . accessToken . expiresOn ) ,
132
- extExpiresOn : new Date ( cacheRecord . accessToken . extendedExpiresOn ) ,
133
- familyId : serverTokenResponse . foci || null ,
134
- state : requestStateObj ? requestStateObj . userRequestState : ""
135
- } ;
119
+ this . cacheStorage . saveCacheRecord ( cacheRecord ) ;
136
120
137
- return authenticationResult ;
138
- }
139
-
140
- /**
141
- * Generate Account
142
- * @param serverTokenResponse
143
- * @param idToken
144
- * @param authority
145
- */
146
- generateAccountEntity ( serverTokenResponse : ServerAuthorizationTokenResponse , idToken : IdToken , authority : Authority ) : AccountEntity {
147
- const authorityType = authority . authorityType ;
148
-
149
- if ( StringUtils . isEmpty ( serverTokenResponse . client_info ) ) {
150
- throw ClientAuthError . createClientInfoEmptyError ( serverTokenResponse . client_info ) ;
151
- }
152
-
153
- return ( authorityType === AuthorityType . Adfs ) ?
154
- AccountEntity . createADFSAccount ( authority , idToken ) :
155
- AccountEntity . createAccount ( serverTokenResponse . client_info , authority , idToken , this . cryptoObj ) ;
121
+ return ResponseHandler . generateAuthenticationResult ( cacheRecord , idTokenObj , false , requestStateObj ? requestStateObj . userRequestState : null ) ;
156
122
}
157
123
158
124
/**
@@ -161,7 +127,7 @@ export class ResponseHandler {
161
127
* @param idTokenObj
162
128
* @param authority
163
129
*/
164
- generateCacheRecord ( serverTokenResponse : ServerAuthorizationTokenResponse , idTokenObj : IdToken , authority : Authority , libraryState ?: LibraryStateObject ) : CacheRecord {
130
+ private generateCacheRecord ( serverTokenResponse : ServerAuthorizationTokenResponse , idTokenObj : IdToken , authority : Authority , libraryState ?: LibraryStateObject ) : CacheRecord {
165
131
// Account
166
132
const cachedAccount = this . generateAccountEntity (
167
133
serverTokenResponse ,
@@ -202,7 +168,7 @@ export class ResponseHandler {
202
168
serverTokenResponse . access_token ,
203
169
this . clientId ,
204
170
idTokenObj . claims . tid ,
205
- responseScopes . asArray ( ) . join ( " " ) ,
171
+ responseScopes . printScopes ( ) ,
206
172
tokenExpirationSeconds ,
207
173
extendedTokenExpirationSeconds
208
174
) ;
@@ -218,4 +184,50 @@ export class ResponseHandler {
218
184
219
185
return new CacheRecord ( cachedAccount , cachedIdToken , cachedAccessToken , cachedRefreshToken ) ;
220
186
}
187
+
188
+ /**
189
+ * Generate Account
190
+ * @param serverTokenResponse
191
+ * @param idToken
192
+ * @param authority
193
+ */
194
+ private generateAccountEntity ( serverTokenResponse : ServerAuthorizationTokenResponse , idToken : IdToken , authority : Authority ) : AccountEntity {
195
+ const authorityType = authority . authorityType ;
196
+
197
+ if ( StringUtils . isEmpty ( serverTokenResponse . client_info ) ) {
198
+ throw ClientAuthError . createClientInfoEmptyError ( serverTokenResponse . client_info ) ;
199
+ }
200
+
201
+ return ( authorityType === AuthorityType . Adfs ) ?
202
+ AccountEntity . createADFSAccount ( authority , idToken ) :
203
+ AccountEntity . createAccount ( serverTokenResponse . client_info , authority , idToken , this . cryptoObj ) ;
204
+ }
205
+
206
+ /**
207
+ * Creates an @AuthenticationResult from @CacheRecord , @IdToken , and a boolean that states whether or not the result is from cache.
208
+ *
209
+ * Optionally takes a state string that is set as-is in the response.
210
+ *
211
+ * @param cacheRecord
212
+ * @param idTokenObj
213
+ * @param fromTokenCache
214
+ * @param stateString
215
+ */
216
+ static generateAuthenticationResult ( cacheRecord : CacheRecord , idTokenObj : IdToken , fromTokenCache : boolean , stateString ?: string ) : AuthenticationResult {
217
+ const responseScopes = ScopeSet . fromString ( cacheRecord . accessToken . target ) ;
218
+ return {
219
+ uniqueId : idTokenObj . claims . oid || idTokenObj . claims . sub ,
220
+ tenantId : idTokenObj . claims . tid ,
221
+ scopes : responseScopes . asArray ( ) ,
222
+ account : cacheRecord . account . getAccountInfo ( ) ,
223
+ idToken : idTokenObj . rawIdToken ,
224
+ idTokenClaims : idTokenObj . claims ,
225
+ accessToken : cacheRecord . accessToken . secret ,
226
+ fromCache : fromTokenCache ,
227
+ expiresOn : new Date ( Number ( cacheRecord . accessToken . expiresOn ) * 1000 ) ,
228
+ extExpiresOn : new Date ( Number ( cacheRecord . accessToken . extendedExpiresOn ) * 1000 ) ,
229
+ familyId : cacheRecord . refreshToken . familyId || null ,
230
+ state : stateString || ""
231
+ } ;
232
+ }
221
233
}
0 commit comments