jeudi 30 janvier 2020

in asp.net web api ,How to customize error message of owin OAuthAuthorizationServerProvider?

public static class ContextHelper { public static void SetCustomError(this OAuthGrantResourceOwnerCredentialsContext context, string errorMessage, bool status) { var json = new ErrorMessage(errorMessage, status).ToJsonString();

       //context.SetError(json);            
       context.Response.Write(json);
   }

   public static string ToJsonString(this object obj)
   {
       return JsonConvert.SerializeObject(obj);
   }

}

public class ErrorMessage { public ErrorMessage(string message, bool status) { Message = message; Status = status; } public string Message { get; private set; } public bool Status { get; private set; } }

if (user == null) { ContextHelper.SetCustomError(context, "Provided username and password is not matching, Please retry.", false); return; }

I get "syntax error". Because text response is:

{"access_token":null,"message":"The user name or password is incorrect"}{"error":" "}

I can't remove {"error":" "}

is there any way to remove {"error":" "}




Aucun commentaire:

Enregistrer un commentaire