I'm adding Strava to an iOS application, Strava uses Auth2.0, every Strava API call needs a token to prove the user is authenticated and the app has permission to access the API. After obtaining a special "code" from user login response, I need to exchange it with Strava to get a token. I try to retrieve the token using the "code" I got from the login like this:
var headers : HTTPHeaders {
get {
return [
"Accept": "application/json",
]
}
}
let par =
["client_secret": "671333e8c4a7726a5160adb615b74a428535f86e",
"client_id": "32573",
"code": "4/7wAZ8rA_jMXwponVhwGKuPmCDP4UGuCViojCq-K5KRiZ1CI1Gzqc2TdglTJ7k1DU2wIxH22fNguNNXTfIGpaD8g"] as [String : Any]
Alamofire.request("https://www.strava.com/oauth/token", method: .post, parameters: par, encoding: JSONEncoding.default, headers: headers)
.validate()
.responseJSON { response in
print("Response -> \(response.debugDescription)")
}
The problem is that I always get a 400 Bad request, if anyone have experience with the Strava API or any idea of what I'm doing wrong please advise.
You have to specify grant_type=authorization_code to tells the token endpoint that the application is using the authorization code grant type:
https://www.strava.com/oauth/token?
client_id=<YOUR_CLIENT_ID>&
client_secret=<YOUR_CLIENT_SECRET>&
code=<AUTHORIZATION_CODE_FROM_STRAVA>&
grant_type=authorization_code
Related
I have been using MediaWiki API for some time using properly formatted URLs, but i need to access a wiki with a required login.
I tried using fetch to make the request, and also axios, and the result is the same: the HTML page of the API, the same I would get if i just put the URL of the api in a browser.
My axios call is this:
axios.post('/wiki/api.php', {
logintoken: "this. Token",
action: "clientlogin",
username: "xxxxx",
password: "yyyyyy",
loginreturnurl: "http://localhost/",
format: "json"
}).then(function (response) {
console.log(response. Data);
})
It is as if the post request is simply not made. I tested using the Wikipedia api, and the result is the same.
Any help?
I believe you should add a ?format=json parameter?
Even though it is a post request
In the end it all came down to the fact that the MediaWiki API was expecting the parameters in the application/x-www-form-urlencoded format, and not application/json or text/plain ones.
When I changed that, I was able to login as expected, regardless of using axios or simply fetch.
The final code looks like this (token obtained via another API call):
const opts = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
"logintoken": this.token,
"action": "clientlogin",
"username": "username",
"password": "password",
"loginreturnurl": "http://localhost/",
"format": "json"
})
};
const res = await fetch('/wiki/api.php', opts).
I am creating a company page (outside Foundry) which will use Foundry for authentication. I would like to show the name and email of the person who logged in in my website, is there a way to get it from the obtained token?
I checked the (internal) documentation pages for multipass and resource policy manager but could not see anything that would help.
You can call the user_info endpoint of multipass:
def get_user_info(self, hostname: str, auth_token: str) -> dict:
"""
Returns the multipass user info
Returns: dict, example:
{
'id': '1234bda5-686e-4fcb-ad52-d95e4281d99f',
'username': '<username>',
'attributes': {'multipass:email:primary': ['...'],...}
}
"""
response = requests.get(
f"{hostname}/multipass/api/me", headers={
"content-type": "application/json",
"authorization": f"Bearer {auth_token}",
}
)
response.raise_for_status()
return response.json()
I'm building an integration between NetSuite and the PayTrace credit card processing service. I have no trouble obtaining an authentication key from PayTrace. However, for some reason when sending a request using nlapiRequestURL(url, postData, headers, httpMethod), I get a 401 error and the value of "The access token is invalid" in the response header information. But, if I make the same request with the same token in Postman, it works just as it should. Here's a sample of the request headers I add to the request (as indicated in the PayTrace API documentation):
[
{ "Authorization" : "Bearer XXXXXXXXXX:XXXXXXXXXX:XXXXXXXXXX" }
, { "Content-Type" : "application/json" }
, { "Cache-Control" : "no-cache" }
]
Is it possible that Postman is adding a header value that allows proper authentication that NetSuite does not? For the life of me I can't quite understand why a valid token won't be accepted form one system but get accepted from a different system. I was able to pull these additional header values from Postman, if they're useful in figuring out this issue:
[
{ "User-Agent" : "PostmanRuntime/7.21.0" }
, { "Accept" : "*/*" }
, { "Postman-Token" : "96d421d7-c47b-4c58-8462-aece865bc673" }
, { "Host" : "api.paytrace.com" }
, { "Accept-Encoding" : "gzip, deflate" }
, { "Content-Length" : "401" }
, { "Cookie" : "BIGipServeriAPP-paytraceAPI.app~iAPP-paytraceAPI_pool=!QQe1sQcLLr7QlVc1dGILKzdv552p1+6KLUz7ZVVyyyi2jm4f32eA463wj2bBLYLGBMTo5UmUvj4DzNk=; TS0179310f=01bb9fcf1ed38f2fe502d18776cc42820b00dd85ced785a7a00c8aa2120628c8b485e498ef8a8cacad2fe52a52612a9c6c8aee023b02bca74bc7716a8e066a85df49c4acfa" }
, { "Connection" : "keep-alive" }
]
I'm not certain at all as to what headers NetSuite adds to these HTTP requests.
Once again I figure it out myself. I was passing in the headers as an array of header name/value pair objects, but it was just supposed to be a single object of name/value pairs of header info. That solved the problem. I don't know why I did it incorrectly that way, since I've done this sort of thing countless times. Maybe I need a vacation...
I got null value from API
https://sample-sdk-server.instamojo.com/status?" + values from this url when callback from instamojo payment gateway screen
I passed env and transactionId in query string in above url and I got result like ["payment_id": , "amount": , "status": ]
So give me any solution for the same
Is is right to pass sample-sdk-server in url ??
I have the same problem, after some research I got this
Use this API for getting payment response
https://test.instamojo.com/v2/gateway/orders/transaction_id:yourTransectionID/
and pass access token you get as header Bearer token like below
let headers = [
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + self.accessToken,
"cache-control": "no-cache"
]
I'm using Firebase to send push notification.
I successfully set up my project and Firebase console and tested sending notifications through the Firebase console. All work great. Now I'm trying to send notification directly from the app using this guide
The code:
let parameters: [String : Any] = [
"message": [
"notification" : [
"title": "FCM Message",
"body": "This is an FCM Message"
],
"token" : deviceToken
]
]
let headers: [String : String] = [
"Content-Type": "application/json",
"Authorization": "Bearer I_NEED_THIS_TOKEN"
]
Alamofire.request("https://fcm.googleapis.com/v1/projects/my_project_name/messages:send", method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers).responseJSON { (resp) in
print(resp.result.value)
}
Seems that to make the code work I only need a valid Oauth 2.0 token for the service account of the Firebase project. But I don't understand where I can get or request it.
So the question is where/how do I get valid Oauth 2.0 token for the service account of the Firebase project.
Your FCM Server Key can be found on the Cloud Messaging tab of your project settings on the FCM Admin console.
See https://firebase.google.com/docs/cloud-messaging/auth-server for details.
Make sure this is the server key, whose value is available in the Cloud Messaging tab of the Firebase console Settings pane. Android, iOS, and browser keys are rejected by FCM.