private async Task <bool> Authenticate(HttpRequestMessage request, MAuthVersion version)
        {
            var logMessage = "Mauth-client attempting to authenticate request from app with mauth app uuid" +
                             $" {options.ApplicationUuid} using version {version}";

            logger.LogInformation(logMessage);

            var mAuthCore = MAuthCoreFactory.Instantiate(version);
            var authInfo  = GetAuthenticationInfo(request, mAuthCore);
            var appInfo   = await GetApplicationInfo(authInfo.ApplicationUuid).ConfigureAwait(false);

            var signature = await mAuthCore.GetSignature(request, authInfo).ConfigureAwait(false);

            return(mAuthCore.Verify(authInfo.Payload, signature, appInfo.PublicKey));
        }
Пример #2
0
        /// <summary>
        /// Signs an HTTP request with the MAuth-specific authentication information and sends the request to the
        /// inner handler to send to the server as an asynchronous operation.
        /// </summary>
        /// <param name="request">The HTTP request message to sign and send to the server.</param>
        /// <param name="cancellationToken">A cancellation token to cancel operation.</param>
        /// <returns>Returns <see cref="Task{HttpResponseMessage}"/>. The task object representing the asynchronous
        /// operation.</returns>
        protected override async Task <HttpResponseMessage> SendAsync(
            HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (InnerHandler == null)
            {
                InnerHandler = new HttpClientHandler();
            }

            if (options.DisableV1 == false) // default
            {
                // Add headers for V1 protocol as well
                var mAuthCoreV1 = MAuthCoreFactory.Instantiate(MAuthVersion.MWS);
                request = await mAuthCoreV1.Sign(request, options).ConfigureAwait(false);
            }

            // Add headers for V2 protocol
            mAuthCore = MAuthCoreFactory.Instantiate(MAuthVersion.MWSV2);
            request   = await mAuthCore.Sign(request, options).ConfigureAwait(false);

            return(await base
                   .SendAsync(request, cancellationToken)
                   .ConfigureAwait(continueOnCapturedContext: false));
        }