예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnauthorizedResponse"/> class
        /// to inform the client that the bearer token included in the request was rejected.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="exception">The exception.</param>
        /// <returns>The error message.</returns>
        internal static UnauthorizedResponse InvalidToken(IDirectedProtocolMessage request, ProtocolException exception)
        {
            var message = new UnauthorizedResponse(request)
            {
                ErrorCode        = Protocol.BearerTokenErrorCodes.InvalidToken,
                ErrorDescription = exception.Message,
                HttpStatusCode   = System.Net.HttpStatusCode.Unauthorized,
            };

            return(message);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnauthorizedResponse"/> class
        /// to inform the client of the required set of scopes required to perform this operation.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="requiredScopes">The set of scopes required to perform this operation.</param>
        /// <returns>The error message.</returns>
        internal static UnauthorizedResponse InsufficientScope(IDirectedProtocolMessage request, HashSet <string> requiredScopes)
        {
            var message = new UnauthorizedResponse(request)
            {
                HttpStatusCode = System.Net.HttpStatusCode.Forbidden,
                ErrorCode      = Protocol.BearerTokenErrorCodes.InsufficientScope,
                Scope          = requiredScopes,
            };

            return(message);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnauthorizedResponse"/> class
        /// to inform the client that the request was invalid.
        /// </summary>
        /// <param name="exception">The exception.</param>
        /// <param name="version">The version of OAuth 2 that is in use.</param>
        /// <returns>The error message.</returns>
        internal static UnauthorizedResponse InvalidRequest(ProtocolException exception, Version version = null)
        {
            var message = new UnauthorizedResponse(version)
            {
                ErrorCode        = Protocol.BearerTokenErrorCodes.InvalidRequest,
                ErrorDescription = exception.Message,
                HttpStatusCode   = System.Net.HttpStatusCode.BadRequest,
            };

            return(message);
        }