Thursday 21 October 2021

Getting status of 400 - {"error":"invalid_grant"} On Authentication

I created my own website (www.luig.us). I create a basic IDE for SQL server to teach kids SQL, DML only.

It requires the user to enter an username and password at the beginning to get an token to use the service.

On local, everything works fine, but when I put it on my site, hosted by go-daddy, I will get the same message every time and I don't have a clue why.

{"error":"invalid_grant"}

This is my java script code - look for Authorize. Any help is appreciated. I followed this article closely https://www.c-sharpcorner.com/UploadFile/736ca4/token-based-authentication-in-web-api-2/



function Authorize() {
    let bearer = "Basic Q01JUzMwOERTMzA4OndlYkFQSQ=="
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;
    var userNameAndPasswordFilled = (email != "" && password != "");
    if (!userNameAndPasswordFilled) {
        $("#formError").show('fast');
    }
    else {
        var bodyOfRequest = {
            grant_type: "password",
            username: email,
            password: password
        };
        $.ajax({
            type: "POST",
            url: uriManager.access,
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", bearer);
            },
            data: bodyOfRequest,
            success: function (response) {
                sessionStorage.setItem(programKeyWords.BearerToken, response.access_token);
                $('#LogonModal').modal('hide');
            },
            error: function (response) {
                $("#formError").show('fast');
            }
        });
    }
}




from Getting status of 400 - {"error":"invalid_grant"} On Authentication

No comments:

Post a Comment