matrix-js-sdk
Version:
Matrix Client-Server SDK for Javascript
61 lines (55 loc) • 10.9 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.discoverAndValidateAuthenticationConfig = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _oidcClientTs = require("oidc-client-ts");
var _validate = require("./validate");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /*
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.
*/
/**
* @experimental
* Discover and validate delegated auth configuration
* - m.authentication config is present and valid
* - delegated auth issuer openid-configuration is reachable
* - delegated auth issuer openid-configuration is configured correctly for us
* When successful, validated metadata is returned
* @param wellKnown - configuration object as returned
* by the .well-known auto-discovery endpoint
* @returns validated authentication metadata and optionally signing keys
* @throws when delegated auth config is invalid or unreachable
*/
const discoverAndValidateAuthenticationConfig = async authenticationConfig => {
var _await$metadataServic;
const homeserverAuthenticationConfig = (0, _validate.validateWellKnownAuthentication)(authenticationConfig);
// create a temporary settings store so we can use metadata service for discovery
const settings = new _oidcClientTs.OidcClientSettingsStore({
authority: homeserverAuthenticationConfig.issuer,
redirect_uri: "",
// Not known yet, this is here to make the type checker happy
client_id: "" // Not known yet, this is here to make the type checker happy
});
const metadataService = new _oidcClientTs.MetadataService(settings);
const metadata = await metadataService.getMetadata();
const signingKeys = (_await$metadataServic = await metadataService.getSigningKeys()) !== null && _await$metadataServic !== void 0 ? _await$metadataServic : undefined;
(0, _validate.isValidatedIssuerMetadata)(metadata);
return _objectSpread(_objectSpread({}, homeserverAuthenticationConfig), {}, {
metadata,
signingKeys
});
};
exports.discoverAndValidateAuthenticationConfig = discoverAndValidateAuthenticationConfig;
//# sourceMappingURL=discovery.js.map