const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
const require_urn$1 = require('./urn.cjs');
const require_binding_redirect$1 = require('./binding-redirect.cjs');
const require_binding_post$1 = require('./binding-post.cjs');
const require_flow$1 = require('./flow.cjs');
const require_entity$1 = require('./entity.cjs');
const require_binding_simplesign$1 = require('./binding-simplesign.cjs');

//#region ../../node_modules/samlify/build/src/entity-sp.js
var require_entity_sp = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/samlify/build/src/entity-sp.js": ((exports) => {
	var __extends = exports && exports.__extends || (function() {
		var extendStatics = function(d, b) {
			extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d$1, b$1) {
				d$1.__proto__ = b$1;
			} || function(d$1, b$1) {
				for (var p in b$1) if (Object.prototype.hasOwnProperty.call(b$1, p)) d$1[p] = b$1[p];
			};
			return extendStatics(d, b);
		};
		return function(d, b) {
			if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
			extendStatics(d, b);
			function __() {
				this.constructor = d;
			}
			d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
		};
	})();
	var __assign = exports && exports.__assign || function() {
		__assign = Object.assign || function(t) {
			for (var s, i = 1, n = arguments.length; i < n; i++) {
				s = arguments[i];
				for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
			}
			return t;
		};
		return __assign.apply(this, arguments);
	};
	var __importDefault = exports && exports.__importDefault || function(mod) {
		return mod && mod.__esModule ? mod : { "default": mod };
	};
	Object.defineProperty(exports, "__esModule", { value: true });
	exports.ServiceProvider = void 0;
	/**
	* @file entity-sp.ts
	* @author tngan
	* @desc  Declares the actions taken by service provider
	*/
	var entity_1 = __importDefault(require_entity$1.default);
	var urn_1 = require_urn$1.default;
	var binding_redirect_1 = __importDefault(require_binding_redirect$1.default);
	var binding_post_1 = __importDefault(require_binding_post$1.default);
	var binding_simplesign_1 = __importDefault(require_binding_simplesign$1.default);
	var flow_1 = require_flow$1.default;
	function default_1(props) {
		return new ServiceProvider(props);
	}
	exports.default = default_1;
	/**
	* @desc Service provider can be configured using either metadata importing or spSetting
	* @param  {object} spSettingimport { FlowResult } from '../types/src/flow.d';
	
	*/
	var ServiceProvider = function(_super) {
		__extends(ServiceProvider$1, _super);
		/**
		* @desc  Inherited from Entity
		* @param {object} spSetting    setting of service provider
		*/
		function ServiceProvider$1(spSetting) {
			var entitySetting = Object.assign({
				authnRequestsSigned: false,
				wantAssertionsSigned: false,
				wantMessageSigned: false
			}, spSetting);
			return _super.call(this, entitySetting, "sp") || this;
		}
		/**
		* @desc  Generates the login request for developers to design their own method
		* @param  {IdentityProvider} idp               object of identity provider
		* @param  {string}   binding                   protocol binding
		* @param  {function} customTagReplacement     used when developers have their own login response template
		*/
		ServiceProvider$1.prototype.createLoginRequest = function(idp, binding, customTagReplacement) {
			if (binding === void 0) binding = "redirect";
			var nsBinding = urn_1.namespace.binding;
			var protocol = nsBinding[binding];
			if (this.entityMeta.isAuthnRequestSigned() !== idp.entityMeta.isWantAuthnRequestsSigned()) throw new Error("ERR_METADATA_CONFLICT_REQUEST_SIGNED_FLAG");
			var context = null;
			switch (protocol) {
				case nsBinding.redirect: return binding_redirect_1.default.loginRequestRedirectURL({
					idp,
					sp: this
				}, customTagReplacement);
				case nsBinding.post:
					context = binding_post_1.default.base64LoginRequest("/*[local-name(.)='AuthnRequest']", {
						idp,
						sp: this
					}, customTagReplacement);
					break;
				case nsBinding.simpleSign:
					context = binding_simplesign_1.default.base64LoginRequest({
						idp,
						sp: this
					}, customTagReplacement);
					break;
				default: throw new Error("ERR_SP_LOGIN_REQUEST_UNDEFINED_BINDING");
			}
			return __assign(__assign({}, context), {
				relayState: this.entitySetting.relayState,
				entityEndpoint: idp.entityMeta.getSingleSignOnService(binding),
				type: "SAMLRequest"
			});
		};
		/**
		* @desc   Validation of the parsed the URL parameters
		* @param  {IdentityProvider}   idp             object of identity provider
		* @param  {string}   binding                   protocol binding
		* @param  {request}   req                      request
		*/
		ServiceProvider$1.prototype.parseLoginResponse = function(idp, binding, request) {
			var self = this;
			return (0, flow_1.flow)({
				from: idp,
				self,
				checkSignature: true,
				parserType: "SAMLResponse",
				type: "login",
				binding,
				request
			});
		};
		return ServiceProvider$1;
	}(entity_1.default);
	exports.ServiceProvider = ServiceProvider;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_entity_sp();
  }
});
//# sourceMappingURL=entity-sp.cjs.map