/// <summary>
        /// The initialize application endpoint function
        /// </summary>
        public async Task InitializeApplicationEndpointAsync(
            string applicationEndpointUri,
            string callbackUriFormat,
            string resourcesUriFormat,
            string audienceUri,
            string aadClientId,
            string aadClientSecret,
            string appTokenCertThumbprint,
            string instanceId,
            bool isSandBoxEnvionment        = false,
            bool logFullHttpRequestResponse = true)
        {
            this.InstanceId        = instanceId;
            this.ResourceUriFormat = resourcesUriFormat;
            this.CallbackUriFormat = callbackUriFormat;

            var logger = IOCHelper.Resolve <IPlatformServiceLogger>();

            logger.HttpRequestResponseNeedsToBeLogged = logFullHttpRequestResponse;

            ClientPlatformSettings platformSettings = null;

            if (!string.IsNullOrEmpty(appTokenCertThumbprint))
            {
                platformSettings = new ClientPlatformSettings(
                    Guid.Parse(aadClientId),
                    appTokenCertThumbprint,
                    isSandBoxEnvionment
                    );
            }
            else if (!string.IsNullOrEmpty(aadClientSecret))
            {
                platformSettings = new ClientPlatformSettings(
                    aadClientSecret,
                    Guid.Parse(aadClientId),
                    isSandBoxEnvionment
                    );
            }
            else
            {
                throw new InvalidOperationException("Should provide at least one prarameter in aadClientSecret and appTokenCertThumbprint");
            }

            var platform = new ClientPlatform(platformSettings, logger);

            var endpointSettings = new ApplicationEndpointSettings(new SipUri(applicationEndpointUri));

            ApplicationEndpoint = new ApplicationEndpoint(platform, endpointSettings, null);

            var loggingContext = new LoggingContext(Guid.NewGuid());
            await ApplicationEndpoint.InitializeAsync(loggingContext).ConfigureAwait(false);

            await ApplicationEndpoint.InitializeApplicationAsync(loggingContext).ConfigureAwait(false);
        }
Esempio n. 2
0
        /// <summary>
        /// The initialize application endpoint function
        /// </summary>
        public async Task InitializeApplicationEndpointAsync(
            string discoverUri,
            string applicationEndpointUri,
            string callbackUriFormat,
            string resourcesUriFormat,
            string aadClientId,
            string aadClientSecret,
            string aadAuthorityUri,
            string aadCertThumbprint,
            string instanceId,
            bool logFullHttpRequestResponse)
        {
            this.InstanceId        = instanceId;
            this.ResourceUriFormat = resourcesUriFormat;
            this.CallbackUriFormat = callbackUriFormat;

            var logger = IOCHelper.Resolve <IPlatformServiceLogger>();

            logger.HttpRequestResponseNeedsToBeLogged = logFullHttpRequestResponse;

            ClientPlatformSettings platformSettings;

            if (aadClientSecret.Length > 0)
            {
                // AAD auth to app using client secret
                platformSettings = new ClientPlatformSettings(
                    new System.Uri(discoverUri),
                    Guid.Parse(aadClientId),
                    null,
                    aadClientSecret
                    );
            }
            else
            {
                // AAD auth to app using cert
                platformSettings = new ClientPlatformSettings(
                    new System.Uri(discoverUri),
                    Guid.Parse(aadClientId),
                    aadCertThumbprint
                    );
            }

            var platform         = new ClientPlatform(platformSettings, logger);
            var endpointSettings = new ApplicationEndpointSettings(new SipUri(applicationEndpointUri));

            ApplicationEndpoint = new ApplicationEndpoint(platform, endpointSettings, null);

            var loggingContext = new LoggingContext(Guid.NewGuid());
            await ApplicationEndpoint.InitializeAsync(loggingContext).ConfigureAwait(false);

            await ApplicationEndpoint.InitializeApplicationAsync(loggingContext).ConfigureAwait(false);
        }