Giter Site home page Giter Site logo

Comments (13)

andysousa avatar andysousa commented on August 24, 2024 1

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.

pixelbucket-dev avatar pixelbucket-dev commented on August 24, 2024

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.

pixelbucket-dev avatar pixelbucket-dev commented on August 24, 2024

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.

pixelbucket-dev avatar pixelbucket-dev commented on August 24, 2024

Thanks @andysousa , really appreciated.

from http.

mlynch avatar mlynch commented on August 24, 2024

PR welcome if you have something soon, if not I can take a look in a few days

from http.

andysousa avatar andysousa commented on August 24, 2024

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.

mlynch avatar mlynch commented on August 24, 2024

@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.

andysousa avatar andysousa commented on August 24, 2024

@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.

andysousa avatar andysousa commented on August 24, 2024

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.

andysousa avatar andysousa commented on August 24, 2024

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.

andysousa avatar andysousa commented on August 24, 2024

@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.

andysousa avatar andysousa commented on August 24, 2024

ok, PR updated... give that a spin

from http.

pixelbucket-dev avatar pixelbucket-dev commented on August 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.