JS code generation fails when Api contains BasicAuth #672

Open
kseo opened this Issue Jan 17, 2017 · 8 comments

Comments

Projects
None yet
5 participants

kseo commented Jan 17, 2017

writeJSForAPI fails to type check after I add BasicAuth to my api.

/Users/kseo/KodeBoxProjects/kodebox-server/jsgen/Main.hs: 21, 15
• No instance for (servant-foreign-0.8.1:Servant.Foreign.Internal.HasForeign
                     NoTypes
                     Servant.API.ContentTypes.NoContent
                     (Servant.API.BasicAuth.BasicAuth
                        "kodebox-realm" Kodebox.Server.Types.Session
                      Servant.API.Sub.:> Kodebox.Server.Api.PrivateApi))
    arising from a use of ‘writeJSForAPI’
• In the expression:
    writeJSForAPI
      restApi vanillaJS (joinPath [outputDir, "Kodebox.js"])
  In an equation for ‘writeJSCode’:
      writeJSCode
        = writeJSForAPI
            restApi vanillaJS (joinPath [outputDir, "Kodebox.js"])
Member

arianvp commented Jan 17, 2017

Hmm I remember I implemented this at some point, but perhaps it never ended up in master.

arianvp self-assigned this Jan 17, 2017

arianvp added this to the 0.10 milestone Jan 17, 2017

Member

phadej commented Jan 19, 2017 edited

Related/Duplicates: #463 #672 #465

@arianvp you have an opportunity to close 3 issues with one PR! See also #682

Member

arianvp commented Jan 31, 2017

@phadej Due to exams wasn't able to finish this week. however I don't think this should block the 0.10 release. We can do a 0.10.1 release as the changes are non-breaking

arianvp removed this from the 0.10 milestone Jan 31, 2017

Member

phadej commented Jan 31, 2017

@arianvp ack.

Just had the same issue. How can I help?

Member

arianvp commented Feb 9, 2017

A HasForeign instance has to be written for the BasicAuth stuff. Which generates enough information such that servant-js can write auth client code.

Which should be the trivial part: https://stackoverflow.com/questions/5507234/how-to-use-basic-auth-with-jquery-and-ajax

I am a bit busy, so I haven't gotten around doing it yet.

I've just been bitten by this one as well. I'm also willing to help...

Has it just been forgotten for a while? :) It sounded like it was close to being solved.

Member

arianvp commented Mar 27, 2017 edited

Yes I haven't had the time to implement it yet. It is not a hard fix I think. If you want to take a shot at it, i'm willing to help! It shouldn't be more than 20 lines of code I assume. We just need to add that extra HasForeign instance that adds the neccesery javascript code to make a basicauth call.

Which in jQuery is:

beforeSend: function (xhr) {
    xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
},

but finding an equivalent for axios and angular and plain XHR should not be hard. we just need to set the request header. We already do this for the Header HasForeign instance which you can look at for inspiration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment