@forgerock/javascript-sdk
Advanced tools
Comparing version 2.0.0-alpha2 to 2.0.0-alpha3
@@ -83,3 +83,3 @@ var __assign = (this && this.__assign) || function () { | ||
var metadata = metadataCallback.getOutputValue('data'); | ||
if (metadata.acceptableCredentials) { | ||
if (metadata.allowCredentials) { | ||
return WebAuthnStepType.Authentication; | ||
@@ -292,5 +292,5 @@ } | ||
FRWebAuthn.createAuthenticationPublicKey = function (metadata) { | ||
var acceptableCredentials = metadata.acceptableCredentials, challenge = metadata.challenge, relyingPartyId = metadata.relyingPartyId, timeout = metadata.timeout; | ||
var allowCredentials = metadata.allowCredentials, challenge = metadata.challenge, relyingPartyId = metadata.relyingPartyId, timeout = metadata.timeout; | ||
var rpId = parseRelyingPartyId(relyingPartyId); | ||
return __assign({ allowCredentials: parseCredentials(acceptableCredentials), challenge: Uint8Array.from(atob(challenge), function (c) { return c.charCodeAt(0); }).buffer, timeout: timeout }, (rpId && { rpId: rpId })); | ||
return __assign({ allowCredentials: parseCredentials(allowCredentials), challenge: Uint8Array.from(atob(challenge), function (c) { return c.charCodeAt(0); }).buffer, timeout: timeout }, (rpId && { rpId: rpId })); | ||
}; | ||
@@ -297,0 +297,0 @@ /** |
@@ -19,3 +19,3 @@ import HiddenValueCallback from '../fr-auth/callbacks/hidden-value-callback'; | ||
interface WebAuthnAuthenticationMetadata { | ||
acceptableCredentials: string; | ||
allowCredentials: string; | ||
challenge: string; | ||
@@ -22,0 +22,0 @@ relyingPartyId: string; |
@@ -58,3 +58,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import { withTimeout } from '../util/timeout'; | ||
import { buildTxnAuthOptions, examineForIGTxnAuth, examineForRESTTxnAuth, hasTransactionAdvice, isAuthStep, newTokenRequired, normalizeIGJSON, normalizeRESTJSON, } from './util'; | ||
import { addTxnIDAndTokenToURL, buildTxnAuthOptions, examineForIGTxnAuth, examineForRESTTxnAuth, hasTransactionAdvice, isAuthStep, newTokenRequired, normalizeIGJSON, normalizeRESTJSON, } from './util'; | ||
/** | ||
@@ -75,3 +75,3 @@ * HTTP client that includes bearer token injection and refresh. | ||
return __awaiter(this, void 0, void 0, function () { | ||
var res, txnAuthJSON, _a, realmPath, serverConfig, txnAuthOptions, initialStep, err_1; | ||
var res, txnAuthJSON, _a, realmPath, serverConfig, txnAuthOptions, initialStep, tokens, err_1; | ||
return __generator(this, function (_b) { | ||
@@ -88,3 +88,3 @@ switch (_b.label) { | ||
case 3: | ||
if (!(options.txnAuth && options.txnAuth.handleStep)) return [3 /*break*/, 14]; | ||
if (!(options.txnAuth && options.txnAuth.handleStep)) return [3 /*break*/, 15]; | ||
if (!(res.redirected && examineForIGTxnAuth(res))) return [3 /*break*/, 4]; | ||
@@ -101,3 +101,3 @@ txnAuthJSON = normalizeIGJSON(res); | ||
case 7: | ||
if (!(txnAuthJSON && txnAuthJSON.advices)) return [3 /*break*/, 14]; | ||
if (!(txnAuthJSON && txnAuthJSON.advices)) return [3 /*break*/, 15]; | ||
_a = Config.get(options.txnAuth.config), realmPath = _a.realmPath, serverConfig = _a.serverConfig; | ||
@@ -118,3 +118,3 @@ txnAuthOptions = buildTxnAuthOptions(txnAuthJSON, serverConfig.baseUrl, options.timeout, realmPath, serverConfig.paths); | ||
case 10: | ||
_b.trys.push([10, 13, , 14]); | ||
_b.trys.push([10, 14, , 15]); | ||
// Walk through auth tree | ||
@@ -125,13 +125,16 @@ return [4 /*yield*/, this.stepIterator(initialStep, options.txnAuth.handleStep)]; | ||
_b.sent(); | ||
// Add Txn ID to *original* request options | ||
options.txnAuth.txnID = txnAuthJSON.advices.TransactionConditionAdvice[0]; | ||
return [4 /*yield*/, TokenStorage.get()]; | ||
case 12: | ||
tokens = _b.sent(); | ||
// Update URL with txn ID | ||
options.url = addTxnIDAndTokenToURL(options.url, txnAuthJSON.advices, tokens); | ||
return [4 /*yield*/, this._request(options, false)]; | ||
case 12: | ||
case 13: | ||
// Retry original resource request | ||
res = _b.sent(); | ||
return [3 /*break*/, 14]; | ||
case 13: | ||
return [3 /*break*/, 15]; | ||
case 14: | ||
err_1 = _b.sent(); | ||
throw new Error(err_1); | ||
case 14: return [2 /*return*/, res]; | ||
case 15: return [2 /*return*/, res]; | ||
} | ||
@@ -141,13 +144,11 @@ }); | ||
}; | ||
HttpClient.setAuthHeaders = function (headers, options, forceRenew) { | ||
HttpClient.setAuthHeaders = function (headers, forceRenew) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var txnAuthRequest, tokens; | ||
var tokens; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
txnAuthRequest = options.txnAuth && options.txnAuth.handleStep; | ||
return [4 /*yield*/, TokenStorage.get()]; | ||
case 0: return [4 /*yield*/, TokenStorage.get()]; | ||
case 1: | ||
tokens = _a.sent(); | ||
if (!tokens.accessToken) return [3 /*break*/, 3]; | ||
if (!(tokens && tokens.accessToken)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, TokenManager.getTokens({ forceRenew: forceRenew })]; | ||
@@ -158,14 +159,4 @@ case 2: | ||
headers.set('Authorization', "Bearer " + tokens.accessToken); | ||
if (txnAuthRequest) { | ||
headers.set('X-Id-Token', tokens.idToken || ''); | ||
headers.set('X-Txn-Id', (options.txnAuth && options.txnAuth.txnID) || ''); | ||
} | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
// If no access tokens, OAuth is not being used. | ||
if (txnAuthRequest) { | ||
headers.set('X-Txn-Id', (options.txnAuth && options.txnAuth.txnID) || ''); | ||
} | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, headers]; | ||
_a.label = 3; | ||
case 3: return [2 /*return*/, headers]; | ||
} | ||
@@ -229,3 +220,3 @@ }); | ||
if (!!options.bypassAuthentication) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.setAuthHeaders(headers, options, forceRenew)]; | ||
return [4 /*yield*/, this.setAuthHeaders(headers, forceRenew)]; | ||
case 1: | ||
@@ -232,0 +223,0 @@ headers = _a.sent(); |
import { ConfigOptions } from '../config/interfaces'; | ||
import FRStep from '../fr-auth/fr-step'; | ||
export interface Advices { | ||
TransactionConditionAdvice: string[]; | ||
} | ||
export declare type HandleStep = (step: FRStep) => Promise<FRStep>; | ||
@@ -32,6 +35,4 @@ /** | ||
}; | ||
advices: { | ||
TransactionConditionAdvice: string[]; | ||
} | null; | ||
advices: Advices | null; | ||
ttl: number; | ||
} |
@@ -7,3 +7,5 @@ /** | ||
import { CustomPathConfig } from '../config/interfaces'; | ||
import { HttpClientRequestOptions, RequiresNewTokenFn, TxnAuthJSON } from './interfaces'; | ||
import { Advices, HttpClientRequestOptions, RequiresNewTokenFn, TxnAuthJSON } from './interfaces'; | ||
import { Tokens } from '../shared/interfaces'; | ||
export declare function addTxnIDAndTokenToURL(url: string, advices: Advices, tokens?: Tokens): string; | ||
export declare function buildTxnAuthOptions(txnAuthObj: TxnAuthJSON, baseURL: string, timeout: number, realmPath?: string, customPaths?: CustomPathConfig): HttpClientRequestOptions; | ||
@@ -10,0 +12,0 @@ export declare function examineForIGTxnAuth(res: Response): boolean; |
@@ -38,2 +38,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { getEndpointPath, resolve, stringify } from '../util/url'; | ||
export function addTxnIDAndTokenToURL(url, advices, tokens) { | ||
var txId = advices.TransactionConditionAdvice[0]; | ||
// Add Txn ID to *original* request options as URL param | ||
var updatedURL = new URL(url); | ||
updatedURL.searchParams.append('_txid', txId); | ||
// If tokens are used, send idToken (JWT) | ||
if (tokens && tokens.idToken) { | ||
updatedURL.searchParams.append('_idtoken', tokens.idToken); | ||
} | ||
return updatedURL.toString(); | ||
} | ||
export function buildTxnAuthOptions(txnAuthObj, baseURL, timeout, realmPath, customPaths) { | ||
@@ -60,2 +71,5 @@ var advices = txnAuthObj.advices ? txnAuthObj.advices.TransactionConditionAdvice : []; | ||
credentials: 'include', | ||
headers: { | ||
'Accept-API-Version': 'resource=2.0, protocol=1.0', | ||
}, | ||
}, | ||
@@ -62,0 +76,0 @@ timeout: timeout, |
@@ -87,3 +87,3 @@ "use strict"; | ||
var metadata = metadataCallback.getOutputValue('data'); | ||
if (metadata.acceptableCredentials) { | ||
if (metadata.allowCredentials) { | ||
return enums_2.WebAuthnStepType.Authentication; | ||
@@ -296,5 +296,5 @@ } | ||
FRWebAuthn.createAuthenticationPublicKey = function (metadata) { | ||
var acceptableCredentials = metadata.acceptableCredentials, challenge = metadata.challenge, relyingPartyId = metadata.relyingPartyId, timeout = metadata.timeout; | ||
var allowCredentials = metadata.allowCredentials, challenge = metadata.challenge, relyingPartyId = metadata.relyingPartyId, timeout = metadata.timeout; | ||
var rpId = helpers_1.parseRelyingPartyId(relyingPartyId); | ||
return __assign({ allowCredentials: helpers_1.parseCredentials(acceptableCredentials), challenge: Uint8Array.from(atob(challenge), function (c) { return c.charCodeAt(0); }).buffer, timeout: timeout }, (rpId && { rpId: rpId })); | ||
return __assign({ allowCredentials: helpers_1.parseCredentials(allowCredentials), challenge: Uint8Array.from(atob(challenge), function (c) { return c.charCodeAt(0); }).buffer, timeout: timeout }, (rpId && { rpId: rpId })); | ||
}; | ||
@@ -301,0 +301,0 @@ /** |
@@ -19,3 +19,3 @@ import HiddenValueCallback from '../fr-auth/callbacks/hidden-value-callback'; | ||
interface WebAuthnAuthenticationMetadata { | ||
acceptableCredentials: string; | ||
allowCredentials: string; | ||
challenge: string; | ||
@@ -22,0 +22,0 @@ relyingPartyId: string; |
{ | ||
"name": "@forgerock/javascript-sdk", | ||
"version": "2.0.0-alpha2", | ||
"version": "2.0.0-alpha3", | ||
"description": "ForgeRock JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "main": "./lib/", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
795982
13121