Comments (13)
I had started putting together the fix for this to submit a PR and got pulled into a few different directions. I will see if i can get to it and share with you to test out. Not sure if @mlynch is still doing active dev on this.... but would be a quick fix.
from http.
Same problem here. We're trying to do a auth0 request via iOS implementation. The response returns with
data: Object
error: "invalid_request"
error_description: "grant_type is required"
from http.
Our request looks like this
return Http.request({
method: 'POST',
url: 'SOME_ENDPOINT',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
username,
password,
grant_type: 'password',
client_id: 'SOME_CLIENT_ID',
client_secret: 'SOME_CLIENT_SECRET'
}
});
from http.
Thanks @andysousa , really appreciated.
from http.
PR welcome if you have something soon, if not I can take a look in a few days
from http.
I have the web and android one working, but my swift is just not that strong. Maybe you could tell me where to look @mlynch?
This is where the data should be getting set in the mutate function, but that is always nil
func mutate(_ call: CAPPluginCall, _ url: URL, _ method: String, _ headers: [String:String]) {
let data = call.getObject("data")
from http.
@andysousa can you open a PR with the android/web changes and then I can help figure out where the Swift side should happen? Thanks 🙌
from http.
@mlynch i was mistaken, android wasn't working for me either. The CAPPluginCall just doesn't have an object called "data" in it for ios/Android. Guessing thats happening at the Cap runtime level... but haven't dug in yet.
from http.
oh, i see the issue... data is being set with getObject... but for OAuth calls, it needs to be getString(). Not sure the downstream ramifications of this... let me see if i can put something together.
from http.
so using a data object for OAuth works in ios/android... the code is smart enough to check the content type and put it as part of the object correctly. This doesn't work the same in the web implemention, so i will submit a PR so that the web matches the logic in ios/Android.
In the meantime @pixelbucket-dev to for it to work in Native, all you need to do is put the data in an object block. The code you pasted won't work because in OAuth, the body should be one string. So you would want to do this.
const ret = Http.request({
method: 'POST',
url: '/api/auth/connect/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data: {
body: "username=username&password=password&grant_type=password&client_id=something&clientsecret=something"
}
});
from http.
@pixelbucket-dev I was wrong, as i dig deeper into the ios implementation... the way you have it should work, its is doing a queryItems?.append so it will build the string appropriately.
I also don't like my implementation in the PR based on this. So i am going to go back and clean it up.
from http.
ok, PR updated... give that a spin
from http.
@andysousa I had a look at the TS code, looks good.
I remember when I tested our request with this plugin I saw the query params being correctly stringified. Might try again with your body
workaround. Thank you.
from http.
Related Issues (20)
- if http is not maintained, then what is the recommended plugin? HOT 2
- Allow fragments to be parsed as JSON in response data
- Could not cast value of type '__NSCFNumber' (0x10881b608) to 'NSString' (0x1f473fc40). HOT 1
- Allow WebDAV HTTP methods
- Sending request on background HOT 2
- Setup custom values in header not work.
- Request to https domain fails with SSLHandshakeException. HOT 5
- cannot overwrite default request headers on ios
- JSONException on device when getting a primitive value, e.g. number
- [feat] support metadata for uploadFile HOT 1
- downloadFile method not working correctly on Android
- Http progress listener has serious performance issue on Android HOT 3
- Cannot get cookies in the response
- iOS and Android handle form-uurlencoded requests differently HOT 2
- How to write interceptor in capacitor http HOT 1
- https url is not hitting with http-community in IONIC React. HOT 1
- Capacitor v4 support? HOT 4
- setCookie: "errorMessage":"Must provide value"
- Capacitor 4 : Http urls not working (only https) HOT 2
- Unable to open asset URL on Android
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http.