enter image description here
I want to get a new access token, in postman works great but when i try to do it in code, i keep getting an error in my chrome console.
with ajax:
POST https://10.250.252.1:43002/oauth/token net::ERR_CERT_AUTHORITY_INVALID jquery-3.3.1.min.js:2
with axios:
POST https://10.250.252.1:43002/oauth/token net::ERR_CERT_AUTHORITY_INVALID jquery-3.3.1.min.js:2
and
Uncaught (in promise) Error: Network Error
at e.exports (spread.js:25)
at XMLHttpRequest.l.onerror (spread.js:25)
the code i use:
$.ajax({
method:"POST",
url: `https://10.250.252.1:43002/oauth/token`,
contentType:"application/json; charset=utf-8",
data: {
grant_type:"password",
username:'user',
password:'user',
client_id:'11111111111111111',
client_secret:'1111'
}
}).done(
function(response) {
console.log(response);
});
axios.request({
url: "https://10.250.252.1:43002/oauth/token",
method: "post",
'content-type':'application/x-www-form-urlencoded',
auth: {
username: "user",
password: "user"
},
data: {
grant_type: "password",
client_id:'11111111111111111',
client_secret:'1111',
scope: "public"
}
})
.then(function(res) {
console.log(res);
});
Its SSL certificate error you need first open the URL in address bar and import the certificate to the browser.
Related
I have a local endpoint that checks if I'm logged in and if yes, it generates token and redirects me to another API endpoint. I want to test the redirection however, I'm ending with the following error:
cy.visit() failed trying to load:
http://getmantaportal.test/authorize/
The response we received from your web server was:
> 403: Forbidden
This was considered a failure because the status code was not 2xx.
This http request was redirected '1' time to:
- 302: https://example.com/api/?token=eyJ0eXAiOiJKV1QiL
Here is my code:
it('Redirect to Manta Edge if already logged in.', function () {
// Login first.
// [...]
// Go to the endpoint and get redirected immediately.
cy.visit('/authorize/')
cy.url().should('contain', '/api/?token=')
})
Thanks a lot in the advance.
Use nested cy.request calls, you'll need to know all redirects you will get to be authenticated.
See the hypothetical example below.
cy.request({
method: "POST",
url: `YOUR FIRST URL`,
headers: {},
body: {
username: YOUR_USERNAME,
password: YOUR_PASSWORD
},
}).then(function (response) {
var body = response.body;
cy.request({
method: "GET",
url: `YOUR SECOND URL`,
auth: {
bearer: body.access_token,
},
}).then(function (response) {
cy.request({
method: "POST",
url: `YOUR THIRD URL IF EXISTS`,
auth: {
bearer: body.access_token,
},
}).then(function (response) {
response.headers
// If necessary, get the cookies to finish the authentication
});
});
I've checked the gizillion answers to this question and for some reason I can't get this to work.
I get the error:
401 (Unauthorized)
My route is an api route guarded.
My data:
let ajaxMainTemplate = {
'mainTemplate': mainTemplate,
'templateId': templateId,
'_token': accessToken,
}
My ajax call:
$.ajax({
type: 'POST',
url:`../api/aiMainTemplate/${ajaxData.templateId}`,
data: {
_token: ajaxData._token,
ajaxData
},
success: function(response) {
console.log(response)
}
})
I've tried the above to test based on another response. I put the token outside of the ajaxData object. I get the same error. I've also attempted:
$.ajax({
type: 'POST',
url:`../api/aiMainTemplate/${ajaxData.templateId}`,
headers: { 'X-CSRF-TOKEN': ajaxData._token },
data: ajaxData,
success: function(response) {
console.log(response)
}
})
Same.
I've also confirmed the token is there by adding a console.log Any ideas what I'm doing wrong with this?
My url was behind the api protected route so I had to do an ajax call to login into it via ajax.
The credentials are in a variable ajaxData.
$.ajax({
type: 'POST',
url: 'http://127.0.0.1:8000/api/login',
data: ajaxData,
success: function(response) {
shopifyToken = response.success.token;
getListProducts(shopifyToken);
}
});
With the shopify token generated from this login it worked.
I already set the Authorized redirect URI on Google API Concole as below show.
Google console API Setting
I used localhost:64420/index to get the code, and send the code to localhost:64420/Auth to used ajax post parameter try to get the access token.
Sadly, I got the error message:
{error: "redirect_uri_mismatch", error_description: "Bad Request"}
Here is the script:
<script>
var code = code;
var clientID = client_ID;
var clientSecret = client_Secret;
var redirect_uri = "http://localhost:64420/Report.aspx";
var searchurl = "https://www.googleapis.com/oauth2/v4/token";
$.ajax({
dataType: "json",
url: searchurl,
data: { code: code, client_id: clientID, client_secret: clientSecret, redirect_uri: redirect_uri, grant_type: 'authorization_code' },
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
crossDomain: true,
cache: true,
success: function (data) {
alert(data);
},
error: function (jqXHR, exception, errorstr) {
console.log(jqXHR);
alert(errorstr);
}
});
</script>
The redirect URL in your app and the redirect URL you configure in the API console must be an exact character-for-character match. Remember you can configure multiple redirect URLs in the APi Console, so don't be shy and add all possible variants, eg with both http and https. You should really be using https for a redirect URL and I wouldn't be surprised if a future change disallowed plaintext URLs.
I want to consume REST api and for that I have only url and the authentication token. I am using Jquery Ajax call for this purpose. I am getting error
Uncaught SyntaxError: Unexpected token :
Below is my code sample
$.ajax({
type: 'GET',
url: "https://xxxx",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
crossDomain: true,
data: { "api_token": "xxxx", "api_token_secret": "xxx" },
success: function (data) {
console.log(data);
},
error: function (data) {
alert("error");
}
});
this code is in jsfile and that js file I am included in index.html page. on document ready I am calling this function.
If I didn't add the datatype : jsonp it is giving error of
XMLHttpRequest cannot load Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value
Can anyone please help me? What is the issue?
This line:
data: { "api_token": "xxxx", "api_token_secret": "xxx" },
should be this:
data: { api_token: "xxxx", api_token_secret: "xxx" },
You shouldn't quote the data keys.
I am trying to perform an AJAX request from a Chrome Extension to Basecamp to authenticate in so I can pull tasks. I have added https://site.basecamphq.com to the permissions in manifest.json. However, when this function is executed, I get this in my console:
XMLHttpRequest cannot load https://site.basecamphq.com. Origin chrome-extension://0123456789 is not allowed by Access-Control-Allow-Origin
$("#login").click(function()
{
$.ajax({
type: "GET",
dataType: 'html',
url: "https://site.basecamphq.com",
username: "username",
password: "X",
success: function(data){
$("#example").append(data);
}
});
});
I have added https://*/ to my manifest.json permissions as well, but no luck.
You need to use background page for doing AJAX requests from a content script.
Background page code:
chrome.extension.onRequest.addListener(function(request, sender, callback) {
$.ajax({
type: "GET",
dataType: 'html',
url: request.url,
username: "username",
password: "X",
success: callback
});
});
Content script code:
chrome.extension.sendRequest({'url': 'https://site.basecamphq.com'}, function(data) {
$("#example").append(data);
});