Skip to content

Commit

Permalink
export all idx, rename old introspect to introspectAuthn
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongranick-okta committed Jan 14, 2022
1 parent 2a6f886 commit 264fe75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
13 changes: 7 additions & 6 deletions lib/OktaAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
transactionStatus,
resumeTransaction,
transactionExists,
introspect,
introspectAuthn,
postToTransaction,
AuthTransaction
} from './tx';
Expand Down Expand Up @@ -98,7 +98,7 @@ import TransactionManager from './TransactionManager';
import { buildOptions } from './options';
import {
interact,
introspect as introspectV2,
introspect,
authenticate,
cancel,
poll,
Expand Down Expand Up @@ -163,7 +163,7 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI {
return storage.get(name);
}
}),
introspect: introspect.bind(null, this)
introspect: introspectAuthn.bind(null, this)
};

this.pkce = {
Expand Down Expand Up @@ -266,7 +266,7 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI {
const boundStartTransaction = startTransaction.bind(null, this);
this.idx = {
interact: interact.bind(null, this),
introspect: introspectV2.bind(null, this),
introspect: introspect.bind(null, this),
authenticate: authenticate.bind(null, this),
register: register.bind(null, this),
start: boundStartTransaction,
Expand Down Expand Up @@ -338,12 +338,13 @@ class OktaAuth implements SDKInterface, SigninAPI, SignoutAPI {
this.options.headers = Object.assign({}, this.options.headers, headers);
}


// Authn V1
async signIn(opts: SigninOptions): Promise<AuthTransaction> {
// TODO: support interaction code flow
// Authn V1 flow
return this.signInWithCredentials(opts as SigninWithCredentialsOptions);
}

// Authn V1
async signInWithCredentials(opts: SigninWithCredentialsOptions): Promise<AuthTransaction> {
opts = clone(opts || {});
const _postToTransaction = (options?) => {
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as crypto from './crypto';

export { default as OktaAuth } from './OktaAuth';
export * from './constants';
export * from './idx';
export * from './types';
export * from './tx';
export * from './errors';
Expand Down
20 changes: 6 additions & 14 deletions lib/tx/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { STATE_TOKEN_KEY_NAME } from '../constants';
import { addStateToken } from './util';
import { AuthTransaction } from './AuthTransaction';

function transactionStatus(sdk, args) {
export function transactionStatus(sdk, args) {
args = addStateToken(sdk, args);
return post(sdk, sdk.getIssuerOrigin() + '/api/v1/authn', args, { withCredentials: true });
}

function resumeTransaction(sdk, args) {
export function resumeTransaction(sdk, args) {
if (!args || !args.stateToken) {
var stateToken = sdk.tx.exists._get(STATE_TOKEN_KEY_NAME);
if (stateToken) {
Expand All @@ -40,7 +40,7 @@ function resumeTransaction(sdk, args) {
});
}

function introspect (sdk, args) {
export function introspectAuthn (sdk, args) {
if (!args || !args.stateToken) {
var stateToken = sdk.tx.exists._get(STATE_TOKEN_KEY_NAME);
if (stateToken) {
Expand All @@ -57,29 +57,21 @@ function introspect (sdk, args) {
});
}

function transactionStep(sdk, args) {
export function transactionStep(sdk, args) {
args = addStateToken(sdk, args);
// v1 pipeline introspect API
return post(sdk, sdk.getIssuerOrigin() + '/api/v1/authn/introspect', args, { withCredentials: true });
}

function transactionExists(sdk) {
export function transactionExists(sdk) {
// We have a cookie state token
return !!sdk.tx.exists._get(STATE_TOKEN_KEY_NAME);
}

function postToTransaction(sdk, url, args, options?) {
export function postToTransaction(sdk, url, args, options?) {
options = Object.assign({ withCredentials: true }, options);
return post(sdk, url, args, options)
.then(function(res) {
return new AuthTransaction(sdk, res);
});
}

export {
transactionStatus,
resumeTransaction,
transactionExists,
postToTransaction,
introspect,
};

0 comments on commit 264fe75

Please sign in to comment.