/* Copyright 2023-2026 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import { hasRequiredStringProperty, isRecord } from "../@types/type-guards.js"; /** * Request body for dynamic registration as defined by https://spec.matrix.org/v1.18/client-server-api/#client-registration */ /** * The OAuth 2.0 grant types that are defined for Matrix in https://spec.matrix.org/v1.17/client-server-api/#grant-types */ export let OAuthGrantType = /*#__PURE__*/function (OAuthGrantType) { /** * As per RFC 6749 section 4.1, the authorization code grant lets the client obtain an access token through a browser redirect. * * See https://spec.matrix.org/v1.18/client-server-api/#authorization-code-grant */ OAuthGrantType["AuthorizationCode"] = "authorization_code"; /** * As per RFC 6749 section 6, the refresh token grant lets the client exchange a refresh token for an access token. * * https://spec.matrix.org/v1.18/client-server-api/#refresh-token-grant */ OAuthGrantType["RefreshToken"] = "refresh_token"; /** * As per RFC 8628, the device authorization grant lets clients on devices with limited input capabilities obtain * an access token by having the user complete authorization on a separate device with a web browser. * * See https://spec.matrix.org/v1.18/client-server-api/#device-authorization-grant */ OAuthGrantType["DeviceAuthorization"] = "urn:ietf:params:oauth:grant-type:device_code"; return OAuthGrantType; }({}); /** * Check that URIs have a common base, * as per https://spec.matrix.org/v1.18/client-server-api/#redirect-uri-validation */ export function urlHasCommonBase(base, urlStr) { if (!urlStr) return false; const url = new URL(urlStr); if (url.protocol !== base.protocol) return false; if (url.hostname !== base.hostname && !url.hostname.endsWith(`.${base.hostname}`)) return false; return true; } /** * Response from dynamic registration */ /** * Validate the given response matches the format expected for a {@link RegistrationResponse} * @param response - the response to validate * @throws if the response does not match the expected format */ export function validateRegistrationResponse(response) { return isRecord(response) && hasRequiredStringProperty(response, "client_id"); } //# sourceMappingURL=register.js.map