Пример #1
0
 public virtual System.Threading.Tasks.Task SignOutAsync(Microsoft.AspNetCore.Http.HttpContext context, string?scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
Пример #2
0
 public static System.Threading.Tasks.Task ChallengeAsync(this Microsoft.AspNetCore.Http.HttpContext context, string?scheme, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
Пример #3
0
 public virtual System.Threading.Tasks.Task SignInAsync(Microsoft.AspNetCore.Http.HttpContext context, string?scheme, System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
Пример #4
0
 public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(string?failureMessage, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
Пример #5
0
 public static Microsoft.AspNetCore.Authentication.AuthenticateResult Fail(System.Exception?failure, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
Пример #6
0
 public AuthenticationTicket(System.Security.Claims.ClaimsPrincipal principal, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties, string?authenticationScheme)
 {
 }
Пример #7
0
 public static System.Threading.Tasks.Task SignOutAsync(this Microsoft.AspNetCore.Http.HttpContext context, Microsoft.AspNetCore.Authentication.AuthenticationProperties?properties)
 {
     throw null;
 }
        /// <summary>
        /// Creates an <see cref="IActionResult"/>  from a <see cref="HttpResponseMessage"/>.
        /// </summary>
        /// <param name="message">The <see cref="HttpResponseMessage"/> to convert.</param>
        /// <param name="location">The location of the created resource. This location is used only when a <see cref="HttpStatusCode.Created"/> is handled.</param>
        /// <param name="authenticationSchemes">The authentication schemes to challenge. This location is used only when a <see cref="HttpStatusCode.Forbidden"/> is handled.</param>
        /// <param name="authenticationProperties"><see cref="AuthenticationProperties"/> used to perform the authentication challenge. This location is used only when a <see cref="HttpStatusCode.Forbidden"/> is handled.</param>
        /// <param name="objectResultTypeIfNotSupported">The type of the <see cref="ObjectResult"/> to convert to if the <see cref="HttpResponseMessage.StatusCode"/> of the specified <paramref name="message"/> if not managed.</param>
        /// <returns>
        /// An <see cref="IActionResult"/>:
        ///     - containing the stringified <see cref="HttpResponseMessage.Content"/> of the specified <paramref name="message"/>.<para/>
        ///     - having its <see cref="IActionResult.StatusCode"/> property set to the <see cref="HttpResponseMessage.StatusCode"/> of the specified <paramref name="message"/>.
        /// </returns>
        /// <remarks>
        /// Only the following status codes are managed:<para/>
        ///     - HttpStatusCode.BadGateway<para/>
        ///     - HttpStatusCode.BadRequest<para/>
        ///     - HttpStatusCode.Conflict<para/>
        ///     - HttpStatusCode.OK<para/>
        ///     - HttpStatusCode.NotFound<para/>
        ///     - HttpStatusCode.Unauthorized<para/>
        ///     - HttpStatusCode.Created<para/>
        ///     - HttpStatusCode.NoContent<para/>
        ///     - HttpStatusCode.Forbidden<para/>
        ///     - UnprocessableEntity (422)
        /// </remarks>
        public static async Task <IActionResult> ToActionResultAsync(this HttpResponseMessage message,
                                                                     List <string>?authenticationSchemes = null,
                                                                     Microsoft.AspNetCore.Authentication.AuthenticationProperties?authenticationProperties = null,
                                                                     Uri?location = null,
                                                                     Type?objectResultTypeIfNotSupported = null)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var messageContent = await message.Content.ReadAsStringAsync();

            ObjectResult?resultingObjectResult;

            switch (message.StatusCode)
            {
            case HttpStatusCode.OK:
                resultingObjectResult = new OkObjectResult(messageContent);
                break;

            case HttpStatusCode.Created:
                resultingObjectResult = new CreatedResult(location, messageContent);
                break;

            case HttpStatusCode.NotFound:
                resultingObjectResult = new NotFoundObjectResult(messageContent);
                break;

            case HttpStatusCode.BadRequest:
                resultingObjectResult = new BadRequestObjectResult(messageContent);
                break;

            case HttpStatusCode.Unauthorized:
                resultingObjectResult = new UnauthorizedObjectResult(messageContent);
                break;

            case HttpStatusCode.BadGateway:
                resultingObjectResult = new BadRequestObjectResult(messageContent);
                break;

            case HttpStatusCode.Conflict:
                resultingObjectResult = new ConflictObjectResult(messageContent);
                break;

            case HttpStatusCode.NoContent:
                return(new NoContentResult());

            case HttpStatusCode.Forbidden:
                return(new ForbidResult(authenticationSchemes, authenticationProperties));

            case HttpStatusCode.InternalServerError:
                return(new StatusCodeResult((int)HttpStatusCode.InternalServerError));

            default:
                if ((int)message.StatusCode == 422)
                {
                    resultingObjectResult = new UnprocessableEntityObjectResult(messageContent);
                }
                else
                {
                    objectResultTypeIfNotSupported ??= typeof(OkObjectResult);
                    resultingObjectResult = Activator.CreateInstance(objectResultTypeIfNotSupported) as ObjectResult;

                    if (resultingObjectResult == null)
                    {
                        throw new InvalidOperationException($"Can not create an instance of the given type {objectResultTypeIfNotSupported}. Should be an {nameof(ObjectResult)}");
                    }

                    resultingObjectResult.Value = messageContent;
                }
                break;
            }

            resultingObjectResult.StatusCode = (int)message.StatusCode;

            return(resultingObjectResult);
        }