Skip to content

Commit

Permalink
Merge pull request authts#116 from authts/reduce-any
Browse files Browse the repository at this point in the history
reduce any
  • Loading branch information
PascalLuginbuehl authored Oct 6, 2021
2 parents 4a3d34d + 2753df4 commit 09dd77b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 47 deletions.
25 changes: 25 additions & 0 deletions docs/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## oidc-client v1.11.5 to oidc-client-ts v2.0.0

Ported library from JavaScript to TypeScript.

**OidcClientSettings:**
- required is now authority
- required is now client_id
- required is now redirect_uri
- renamed clockSkew to clockSkewInSeconds
- renamed staleStateAge to staleStateAgeInSeconds
- removed ResponseValidatorCtor and MetadataServiceCtor, if needed OidcClient/UserManager class must be extended
- default of response_type changed from "id_token" to "code"

**UserManagerSettings:**
- renamed accessTokenExpiringNotificationTime to accessTokenExpiringNotificationTimeInSeconds
- changed silentRequestTimeout (milliseconds) to silentRequestTimeoutInSeconds
- changed checkSessionInterval (milliseconds) to checkSessionIntervalInSeconds
- default of automaticSilentRenew changed from false to true
- default of validateSubOnSilentRenew changed from false to true
- default of includeIdTokenInSilentRenew changed from true to false
- default of monitorSession changed from true to false

**UserManager:**
- signoutPopupCallback to pass optionaly keepOpen as true, second argument must be used
20 changes: 9 additions & 11 deletions docs/oidc-client-ts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export interface CreateSigninRequestArgs {
// (undocumented)
client_secret?: string;
// (undocumented)
data?: any;
// (undocumented)
display?: string;
// (undocumented)
extraQueryParams?: Record<string, any>;
Expand Down Expand Up @@ -85,7 +83,7 @@ export interface CreateSigninRequestArgs {
// Warning: (ae-forgotten-export) The symbol "SignoutRequestArgs" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url"> & {
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url" | "state_data"> & {
state?: any;
};

Expand Down Expand Up @@ -178,11 +176,11 @@ export class OidcClient {
// Warning: (ae-forgotten-export) The symbol "SigninRequest" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createSigninRequest({ response_type, scope, redirect_uri, data, state, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, request, request_uri, response_mode, extraQueryParams, extraTokenParams, request_type, skipUserInfo }: CreateSigninRequestArgs): Promise<SigninRequest>;
createSigninRequest({ response_type, scope, redirect_uri, state, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, request, request_uri, response_mode, extraQueryParams, extraTokenParams, request_type, skipUserInfo }: CreateSigninRequestArgs): Promise<SigninRequest>;
// Warning: (ae-forgotten-export) The symbol "SignoutRequest" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createSignoutRequest({ id_token_hint, data, state, post_logout_redirect_uri, extraQueryParams, request_type }?: CreateSignoutRequestArgs): Promise<SignoutRequest>;
createSignoutRequest({ state, id_token_hint, post_logout_redirect_uri, extraQueryParams, request_type }?: CreateSignoutRequestArgs): Promise<SignoutRequest>;
// (undocumented)
readonly metadataService: MetadataService;
// (undocumented)
Expand Down Expand Up @@ -442,13 +440,13 @@ export class UserManager {
// (undocumented)
signoutPopup(args?: SignoutPopupArgs): Promise<void>;
// (undocumented)
signoutPopupCallback(url: any, keepOpen: any): Promise<void>;
signoutPopupCallback(url?: string, keepOpen?: boolean): Promise<void>;
// (undocumented)
signoutRedirect(args?: SignoutRedirectArgs): Promise<void>;
// (undocumented)
signoutRedirectCallback(url?: string): Promise<SignoutResponse>;
// (undocumented)
protected _signoutStart(args: CreateSignoutRequestArgs | undefined, handle: IWindow): Promise<any>;
protected _signoutStart(args: CreateSignoutRequestArgs | undefined, handle: IWindow): Promise<NavigateResponse>;
// Warning: (ae-forgotten-export) The symbol "SilentRenewService" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -573,10 +571,10 @@ export class WebStorageStateStore implements StateStore {

// Warnings were encountered during analysis:
//
// src/OidcClient.ts:117:88 - (ae-forgotten-export) The symbol "SigninState" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:117:108 - (ae-forgotten-export) The symbol "SigninResponse" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:187:89 - (ae-forgotten-export) The symbol "State" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:187:115 - (ae-forgotten-export) The symbol "SignoutResponse" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:114:88 - (ae-forgotten-export) The symbol "SigninState" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:114:108 - (ae-forgotten-export) The symbol "SigninResponse" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:184:89 - (ae-forgotten-export) The symbol "State" needs to be exported by the entry point index.d.ts
// src/OidcClient.ts:184:115 - (ae-forgotten-export) The symbol "SignoutResponse" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
2 changes: 1 addition & 1 deletion samples/Parcel/src/user-manager/sample-popup-signout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { UserManager, settings } from "./sample-settings";

void new UserManager(settings).signoutPopupCallback(true);
void new UserManager(settings).signoutPopupCallback(undefined, true);
19 changes: 8 additions & 11 deletions src/OidcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface CreateSigninRequestArgs {
response_type?: string;
scope?: string;

data?: any;
// state can be used by a caller to have data round tripped
state?: any;

prompt?: string;
Expand All @@ -45,7 +45,7 @@ export interface CreateSigninRequestArgs {
/**
* @public
*/
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url"> & { state?: any };
export type CreateSignoutRequestArgs = Omit<SignoutRequestArgs, "url" | "state_data"> & { state?: any };

/**
* @public
Expand All @@ -64,11 +64,8 @@ export class OidcClient {

public async createSigninRequest({
response_type, scope, redirect_uri,
// data was meant to be the place a caller could indicate the data to
// have round tripped, but people were getting confused, so i added state (since that matches the spec)
// and so now if data is not passed, but state is then state will be used
// TODO: eliminate data in favor of state
data, state, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
state,
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
resource, request, request_uri, response_mode, extraQueryParams, extraTokenParams, request_type, skipUserInfo
}: CreateSigninRequestArgs): Promise<SigninRequest> {
Log.debug("OidcClient.createSigninRequest");
Expand Down Expand Up @@ -102,7 +99,7 @@ export class OidcClient {
redirect_uri,
response_type,
scope,
data: data || state,
state_data: state,
prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values,
resource, request, request_uri, extraQueryParams, extraTokenParams, request_type, response_mode,
client_secret: this.settings.client_secret,
Expand Down Expand Up @@ -150,8 +147,8 @@ export class OidcClient {
}

public async createSignoutRequest({
// TODO: eliminate data in favor of state
id_token_hint, data, state, post_logout_redirect_uri, extraQueryParams, request_type
state,
id_token_hint, post_logout_redirect_uri, extraQueryParams, request_type
}: CreateSignoutRequestArgs = {}): Promise<SignoutRequest> {
Log.debug("OidcClient.createSignoutRequest");

Expand All @@ -170,7 +167,7 @@ export class OidcClient {
url,
id_token_hint,
post_logout_redirect_uri,
data: data || state,
state_data: state,
extraQueryParams,
request_type
});
Expand Down
6 changes: 3 additions & 3 deletions src/SigninRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SigninRequestArgs {
scope: string;

// optional
data?: any;
state_data?: any;
prompt?: string;
display?: string;
max_age?: number;
Expand All @@ -41,7 +41,7 @@ export class SigninRequest {
// mandatory
url, authority, client_id, redirect_uri, response_type, scope,
// optional
data, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, response_mode,
state_data, prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values, resource, response_mode,
request, request_uri, extraQueryParams, request_type, client_secret, extraTokenParams, skipUserInfo
}: SigninRequestArgs) {
if (!url) {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class SigninRequest {
}

this.state = new SigninState({
data,
data: state_data,
request_type,
nonce: isOidc,
code_verifier: isCode,
Expand Down
8 changes: 4 additions & 4 deletions src/SignoutRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export interface SignoutRequestArgs {
url: string;

// optional
state_data?: any;
id_token_hint?: string;
post_logout_redirect_uri?: string;
data?: string;
extraQueryParams?: Record<string, any>;
request_type?: string;
}
Expand All @@ -22,7 +22,7 @@ export class SignoutRequest {

public constructor({
url,
id_token_hint, post_logout_redirect_uri, data, extraQueryParams, request_type
state_data, id_token_hint, post_logout_redirect_uri, extraQueryParams, request_type
}: SignoutRequestArgs) {
if (!url) {
Log.error("SignoutRequest.ctor: No url passed");
Expand All @@ -36,8 +36,8 @@ export class SignoutRequest {
if (post_logout_redirect_uri) {
url = UrlUtility.addQueryParam(url, "post_logout_redirect_uri", post_logout_redirect_uri);

if (data) {
this.state = new State({ data, request_type });
if (state_data) {
this.state = new State({ data: state_data, request_type });

url = UrlUtility.addQueryParam(url, "state", this.state.id);
}
Expand Down
9 changes: 2 additions & 7 deletions src/UserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,7 @@ export class UserManager {
}, handle);
Log.info("UserManager.signoutPopup: successful");
}
public async signoutPopupCallback(url: any, keepOpen: any): Promise<void> {
if (typeof(keepOpen) === "undefined" && typeof(url) === "boolean") {
keepOpen = url;
url = null;
}

public async signoutPopupCallback(url?: string, keepOpen = false): Promise<void> {
const delimiter = "?";
await this._popupNavigator.callback(url, keepOpen, delimiter);
Log.info("UserManager.signoutPopupCallback: successful");
Expand All @@ -479,7 +474,7 @@ export class UserManager {
const navResponse = await this._signoutStart(args, handle);
return this._signoutEnd(navResponse.url);
}
protected async _signoutStart(args: CreateSignoutRequestArgs = {}, handle: IWindow): Promise<any> {
protected async _signoutStart(args: CreateSignoutRequestArgs = {}, handle: IWindow): Promise<NavigateResponse> {
Log.debug("UserManager._signoutStart: got navigator window handle");

try {
Expand Down
13 changes: 7 additions & 6 deletions test/unit/OidcClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("OidcClient", () => {

// act
const request = await subject.createSigninRequest({
data: "foo",
state: "foo",
response_type: "bar",
response_mode: "mode",
scope: "baz",
Expand Down Expand Up @@ -393,7 +393,7 @@ describe("OidcClient", () => {
id: "1",
nonce: "2",
authority: "authority",
client_id:"client",
client_id: "client",
redirect_uri: "http://cb",
scope: "scope",
request_type: "type"
Expand Down Expand Up @@ -463,7 +463,7 @@ describe("OidcClient", () => {

// act
const request = await subject.createSignoutRequest({
data: "foo",
state: "foo",
post_logout_redirect_uri: "bar",
id_token_hint: "baz"
});
Expand Down Expand Up @@ -514,7 +514,8 @@ describe("OidcClient", () => {

// act
await subject.createSignoutRequest({
data:"foo", id_token_hint:"hint"
state: "foo",
id_token_hint: "hint"
});

// assert
Expand Down Expand Up @@ -582,7 +583,7 @@ describe("OidcClient", () => {

it("should deserialize stored state and return state and response", async () => {
// arrange
const item = new State({ id: "1", request_type:"type" }).toStorageString();
const item = new State({ id: "1", request_type: "type" }).toStorageString();
jest.spyOn(subject.settings.stateStore, "get").mockImplementation(() => Promise.resolve(item));

// act
Expand Down Expand Up @@ -683,7 +684,7 @@ describe("OidcClient", () => {
// arrange
const item = new State({
id: "1",
data:"bar",
data: "bar",
request_type: "type"
});
jest.spyOn(subject.settings.stateStore, "remove")
Expand Down
8 changes: 4 additions & 4 deletions test/unit/SignoutRequest.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { SignoutRequest } from "../../src/SignoutRequest";
import { SignoutRequest, SignoutRequestArgs } from "../../src/SignoutRequest";

describe("SignoutRequest", () => {

let subject: SignoutRequest;
let settings: any;
let settings: SignoutRequestArgs;

beforeEach(() => {
settings = {
url: "http://sts/signout",
id_token_hint: "hint",
post_logout_redirect_uri: "loggedout",
data: { data: "test" }
state_data: { data: "test" }
};
subject = new SignoutRequest(settings);
});
Expand All @@ -22,7 +22,7 @@ describe("SignoutRequest", () => {

it("should require a url param", () => {
// arrange
delete settings.url;
delete (settings as any).url;

// act
try {
Expand Down

0 comments on commit 09dd77b

Please sign in to comment.