New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS code generation fails when Api contains BasicAuth #672
Comments
Hmm I remember I implemented this at some point, but perhaps it never ended up in master. |
@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 ack. |
Just had the same issue. How can I help? |
A HasForeign instance has to be written for the BasicAuth stuff. Which generates enough information such that 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. |
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 Which in jQuery is:
but finding an equivalent for |
Hey just wondering what the status on the issue is? I am using Generalized Authentication provided by
Ideally I would like to use Axios instead of vanilla. |
After some searching and hacking I appear to have found a solution. Creating the following instance for instance forall lang ftype api auths v. ( HasForeign lang ftype api
, HasForeignType lang ftype T.Text
) =>
HasForeign lang ftype (Auth auths v
:> api) where
type Foreign ftype (Auth auths v
:> api) = Foreign ftype api
foreignFor lang Proxy Proxy subR =
foreignFor lang Proxy (Proxy :: Proxy api) req
where
req = subR {_reqHeaders = HeaderArg arg : _reqHeaders subR}
arg =
Arg
{ _argName = PathSegment "Authorization"
, _argType =
typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy T.Text)
} Now I'm pretty new to type level programming so a lot of this is going over my head, I just found a very similar solution online and fought with compiler until the types matched up. The only issue with this solution is the fact that it produces:
I cannot figure out what to change to achieve my desired result. My current solution is to just pass Also, should the above instance be included by default? |
@domenkozar Is it always the case that the |
For reference for anyone attempting this in the future the below change is all that is needed to add req = subR {_reqHeaders = ReplaceHeaderArg arg "Bearer {Authorization}" : _reqHeaders subR}
In relation to supporting new auth stuffs in foreign: Would it be possible to add another (optional) piece of information to the For example: Could this I might be way off here but this would be something I would be very interested in working on if I could receive a few pointers along the way. |
for basic authentication I managed to get away with this orphan instance: instance (HasForeign lang ftype api, HasForeignType lang ftype Text) => HasForeign lang ftype (BasicAuth a b :> api) where
type Foreign ftype (BasicAuth a b :> api) = Foreign ftype api
foreignFor lang proxy1 Proxy subR = foreignFor lang proxy1 (Proxy :: Proxy api) req
where
req = subR {_reqHeaders = HeaderArg arg : _reqHeaders subR}
arg =
Arg
{ _argName = PathSegment "Authorization"
, _argType =
typeFor lang (Proxy :: Proxy ftype) (Proxy :: Proxy Text)
} (I've never done type-level programming with Haskell, this is largely an adaptation of the code by @mcgizzle and from sordina/servant-options#3) |
writeJSForAPI
fails to type check after I addBasicAuth
to my api.The text was updated successfully, but these errors were encountered: