Skip to content

Commit

Permalink
sets useInteractionCodeFlow to true in spa samples and test app
Browse files Browse the repository at this point in the history
adds dynamic signin form to spa samples
sets IdxFeature enum to use human readable strings

export all idx, rename old introspect to introspectAuthn
  • Loading branch information
aarongranick-okta committed Jan 14, 2022
1 parent d209c7c commit c1d715c
Show file tree
Hide file tree
Showing 38 changed files with 673 additions and 361 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
6 changes: 3 additions & 3 deletions lib/idx/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export type NextStep = {
}

export enum IdxFeature {
PASSWORD_RECOVERY,
REGISTRATION,
SOCIAL_IDP,
PASSWORD_RECOVERY = 'recover-password',
REGISTRATION = 'enroll-profile',
SOCIAL_IDP = 'redirect-idp',
}

export interface IdxTransaction {
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,
};
2 changes: 1 addition & 1 deletion samples/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const defaults = {

const spaDefaults = Object.assign({
redirectPath: '/login/callback',
flow: 'redirect',
authMethod: 'form',
scopes: ['openid', 'email'],
storage: 'sessionStorage',
requireUserSession: true,
Expand Down
16 changes: 8 additions & 8 deletions samples/generated/static-spa/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c1d715c

Please sign in to comment.