Files
matrix-quotes-bot/node_modules/matrix-js-sdk/lib/oauth/discover.js
unfunny dfe4cc537f init
2026-09-13 00:29:11 -04:00

35 lines
2.4 KiB
JavaScript

/*
Copyright 2023 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 { hasOptionalStringProperty, hasRequiredStringProperty, isRecord, optionalStringArrayProperty, requiredArrayValue } from "../@types/type-guards.js";
import { OAuthGrantType } from "./index.js";
/**
* Metadata from OAuth 2.0 client authentication API as per
* https://spec.matrix.org/v1.18/client-server-api/#get_matrixclientv1auth_metadata
* With validated properties required in type
*/
/**
* Validates OAuth 2.0 auth metadata as defined by
* https://spec.matrix.org/v1.18/client-server-api/#get_matrixclientv1auth_metadata
* @param authMetadata - json object
* @returns boolean of whether the input is valid
*/
export const isValidAuthMetadata = authMetadata => {
return isRecord(authMetadata) && hasRequiredStringProperty(authMetadata, "issuer") && hasRequiredStringProperty(authMetadata, "authorization_endpoint") && hasRequiredStringProperty(authMetadata, "token_endpoint") && hasRequiredStringProperty(authMetadata, "revocation_endpoint") && hasRequiredStringProperty(authMetadata, "registration_endpoint") && hasOptionalStringProperty(authMetadata, "account_management_uri") && hasOptionalStringProperty(authMetadata, "device_authorization_endpoint") && optionalStringArrayProperty(authMetadata, "account_management_actions_supported") && optionalStringArrayProperty(authMetadata, "prompt_values_supported") && requiredArrayValue(authMetadata, "response_modes_supported", "query") && requiredArrayValue(authMetadata, "response_modes_supported", "fragment") && requiredArrayValue(authMetadata, "response_types_supported", "code") && requiredArrayValue(authMetadata, "grant_types_supported", OAuthGrantType.AuthorizationCode) && requiredArrayValue(authMetadata, "grant_types_supported", OAuthGrantType.RefreshToken) && requiredArrayValue(authMetadata, "code_challenge_methods_supported", "S256");
};
//# sourceMappingURL=discover.js.map