@@ -23,6 +23,7 @@ import { type URLParams } from "../../vector/url_utils.ts";
2323 * @param clientId this client's id as registered with configured issuer
2424 * @param homeserverUrl target homeserver
2525 * @param identityServerUrl OPTIONAL target identity server
26+ * @param isRegistration if true will set the prompt to "create"
2627 * @returns Promise that resolves after we have navigated to auth endpoint
2728 */
2829export const startOidcLogin = async (
@@ -47,7 +48,7 @@ export const startOidcLogin = async (
4748 nonce,
4849 prompt,
4950 urlState : PlatformPeg . get ( ) ?. getOidcClientState ( ) ,
50- responseMode : "fragment" ,
51+ responseMode : delegatedAuthConfig . response_modes_supported ?. includes ( "fragment" ) ? "fragment" : "query ",
5152 } ) ;
5253
5354 window . location . href = authorizationUrl ;
@@ -57,15 +58,20 @@ export const startOidcLogin = async (
5758 * Gets `code` and `state` response params
5859 *
5960 * @param urlParams - the parameters to read
61+ * @param responseMode - the response_mode used in the auth request
6062 * @returns code and state
6163 * @throws when code and state are not valid strings
6264 */
63- const getCodeAndStateFromParams = ( {
64- code,
65- state ,
66- } : NonNullable < URLParams [ "oidc" ] > ) : { code : string ; state : string } => {
65+ const getCodeAndStateFromParams = (
66+ { code, state } : NonNullable < URLParams [ "oidc_fragment" ] > ,
67+ responseMode : "fragment" | "query" ,
68+ ) : { code : string ; state : string } => {
6769 if ( ! code || typeof code !== "string" || ! state || typeof state !== "string" ) {
68- throw new Error ( OidcClientError . InvalidQueryParameters ) ;
70+ if ( responseMode === "fragment" ) {
71+ throw new Error ( OidcClientError . InvalidFragmentParameters ) ;
72+ } else {
73+ throw new Error ( OidcClientError . InvalidQueryParameters ) ;
74+ }
6975 }
7076 return { code, state } ;
7177} ;
@@ -91,15 +97,17 @@ type CompleteOidcLoginResponse = {
9197/**
9298 * Attempt to complete authorization code flow to get an access token
9399 * @param urlParams the parameters extracted from the app-load URI.
100+ * @param responseMode - the response_mode used in the auth request
94101 * @returns Promise that resolves with a CompleteOidcLoginResponse when login was successful
95102 * @throws When we failed to get a valid access token
96103 */
97104export const completeOidcLogin = async (
98- urlParams : NonNullable < URLParams [ "oidc" ] > ,
105+ urlParams : NonNullable < URLParams [ "oidc_fragment" ] > ,
106+ responseMode : "fragment" | "query" ,
99107) : Promise < CompleteOidcLoginResponse > => {
100- const { code, state } = getCodeAndStateFromParams ( urlParams ) ;
108+ const { code, state } = getCodeAndStateFromParams ( urlParams , responseMode ) ;
101109 const { homeserverUrl, tokenResponse, idTokenClaims, identityServerUrl, oidcClientSettings } =
102- await completeAuthorizationCodeGrant ( code , state , "fragment" ) ;
110+ await completeAuthorizationCodeGrant ( code , state , responseMode ) ;
103111
104112 return {
105113 homeserverUrl,
0 commit comments