mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-24 20:14:53 +01:00
Fix typing and tests
This commit is contained in:
parent
30d97d6f41
commit
f7ffae4576
@ -32,6 +32,9 @@ export interface IURLRouter<T> {
|
|||||||
urlForPath(path: Path<T>): string;
|
urlForPath(path: Path<T>): string;
|
||||||
openRoomActionUrl(roomId: string): string;
|
openRoomActionUrl(roomId: string): string;
|
||||||
createSSOCallbackURL(): string;
|
createSSOCallbackURL(): string;
|
||||||
|
createOIDCRedirectURL(): string;
|
||||||
|
absoluteAppUrl(): string;
|
||||||
|
absoluteUrlForAsset(asset: string): string;
|
||||||
normalizeUrl(): void;
|
normalizeUrl(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,8 +33,16 @@ export type SegmentType = {
|
|||||||
"details": true;
|
"details": true;
|
||||||
"members": true;
|
"members": true;
|
||||||
"member": string;
|
"member": string;
|
||||||
"oidc-callback": (string | null)[];
|
"oidc": {
|
||||||
"oidc-error": (string | null)[];
|
state: string,
|
||||||
|
} &
|
||||||
|
({
|
||||||
|
code: string,
|
||||||
|
} | {
|
||||||
|
error: string,
|
||||||
|
errorDescription: string | null,
|
||||||
|
errorUri: string | null ,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createNavigation(): Navigation<SegmentType> {
|
export function createNavigation(): Navigation<SegmentType> {
|
||||||
@ -131,18 +139,21 @@ export function parseUrlPath(urlPath: string, currentNavPath: Path<SegmentType>,
|
|||||||
// Special case for OIDC callback
|
// Special case for OIDC callback
|
||||||
if (urlPath.includes("state")) {
|
if (urlPath.includes("state")) {
|
||||||
const params = new URLSearchParams(urlPath);
|
const params = new URLSearchParams(urlPath);
|
||||||
if (params.has("state")) {
|
const state = params.get("state");
|
||||||
|
const code = params.get("code");
|
||||||
|
const error = params.get("error");
|
||||||
|
if (state) {
|
||||||
// This is a proper OIDC callback
|
// This is a proper OIDC callback
|
||||||
if (params.has("code")) {
|
if (code) {
|
||||||
segments.push(new Segment("oidc", {
|
segments.push(new Segment("oidc", {
|
||||||
state: params.get("state"),
|
state,
|
||||||
code: params.get("code"),
|
code,
|
||||||
}));
|
}));
|
||||||
return segments;
|
return segments;
|
||||||
} else if (params.has("error")) {
|
} else if (error) {
|
||||||
segments.push(new Segment("oidc", {
|
segments.push(new Segment("oidc", {
|
||||||
state: params.get("state"),
|
state,
|
||||||
error: params.get("error"),
|
error,
|
||||||
errorDescription: params.get("error_description"),
|
errorDescription: params.get("error_description"),
|
||||||
errorUri: params.get("error_uri"),
|
errorUri: params.get("error_uri"),
|
||||||
}));
|
}));
|
||||||
@ -514,19 +525,22 @@ export function tests() {
|
|||||||
assert.equal(newPath?.segments[1].value, "b");
|
assert.equal(newPath?.segments[1].value, "b");
|
||||||
},
|
},
|
||||||
"Parse OIDC callback": assert => {
|
"Parse OIDC callback": assert => {
|
||||||
const segments = parseUrlPath("state=tc9CnLU7&code=cnmUnwIYtY7V8RrWUyhJa4yvX72jJ5Yx");
|
const path = createEmptyPath();
|
||||||
|
const segments = parseUrlPath("state=tc9CnLU7&code=cnmUnwIYtY7V8RrWUyhJa4yvX72jJ5Yx", path);
|
||||||
assert.equal(segments.length, 1);
|
assert.equal(segments.length, 1);
|
||||||
assert.equal(segments[0].type, "oidc");
|
assert.equal(segments[0].type, "oidc");
|
||||||
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", code: "cnmUnwIYtY7V8RrWUyhJa4yvX72jJ5Yx"});
|
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", code: "cnmUnwIYtY7V8RrWUyhJa4yvX72jJ5Yx"});
|
||||||
},
|
},
|
||||||
"Parse OIDC error": assert => {
|
"Parse OIDC error": assert => {
|
||||||
const segments = parseUrlPath("state=tc9CnLU7&error=invalid_request");
|
const path = createEmptyPath();
|
||||||
|
const segments = parseUrlPath("state=tc9CnLU7&error=invalid_request", path);
|
||||||
assert.equal(segments.length, 1);
|
assert.equal(segments.length, 1);
|
||||||
assert.equal(segments[0].type, "oidc");
|
assert.equal(segments[0].type, "oidc");
|
||||||
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", error: "invalid_request", errorUri: null, errorDescription: null});
|
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", error: "invalid_request", errorUri: null, errorDescription: null});
|
||||||
},
|
},
|
||||||
"Parse OIDC error with description": assert => {
|
"Parse OIDC error with description": assert => {
|
||||||
const segments = parseUrlPath("state=tc9CnLU7&error=invalid_request&error_description=Unsupported%20response_type%20value");
|
const path = createEmptyPath();
|
||||||
|
const segments = parseUrlPath("state=tc9CnLU7&error=invalid_request&error_description=Unsupported%20response_type%20value", path);
|
||||||
assert.equal(segments.length, 1);
|
assert.equal(segments.length, 1);
|
||||||
assert.equal(segments[0].type, "oidc");
|
assert.equal(segments[0].type, "oidc");
|
||||||
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", error: "invalid_request", errorDescription: "Unsupported response_type value", errorUri: null});
|
assert.deepEqual(segments[0].value, {state: "tc9CnLU7", error: "invalid_request", errorDescription: "Unsupported response_type value", errorUri: null});
|
||||||
|
@ -15,7 +15,8 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type {RequestFunction} from "../../platform/types/types";
|
import type {RequestFunction} from "../../platform/types/types";
|
||||||
import type {URLRouter} from "../../domain/navigation/URLRouter.js";
|
import type {IURLRouter} from "../../domain/navigation/URLRouter.js";
|
||||||
|
import type {SegmentType} from "../../domain/navigation";
|
||||||
|
|
||||||
const WELL_KNOWN = ".well-known/openid-configuration";
|
const WELL_KNOWN = ".well-known/openid-configuration";
|
||||||
|
|
||||||
@ -69,12 +70,12 @@ const clientIds: Record<IssuerUri, ClientConfig> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export class OidcApi {
|
export class OidcApi<N extends object = SegmentType> {
|
||||||
_issuer: string;
|
_issuer: string;
|
||||||
_requestFn: RequestFunction;
|
_requestFn: RequestFunction;
|
||||||
_encoding: any;
|
_encoding: any;
|
||||||
_crypto: any;
|
_crypto: any;
|
||||||
_urlCreator: URLRouter;
|
_urlCreator: IURLRouter<N>;
|
||||||
_metadataPromise: Promise<any>;
|
_metadataPromise: Promise<any>;
|
||||||
_registrationPromise: Promise<any>;
|
_registrationPromise: Promise<any>;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user