Open john-goldsmith opened 6 years ago
You can override applyAuthToRequest
the following way:
const apiClient = require('../service/ApiClient.js');
const client = apiClient.instance;
client.applyAuthToRequest = function(request) {
const _end = request._end;
request._end = function() {
request.req.setHeader('Authorization', computeAuthorizationHeader(request));
_end.call(request);
}
return request;
};
I have what I suspect to be an "Authentication 101" type question, but am unsure of the approach when using a generated JavaScript client in the context of a SPA (React, specifically). I configure my SDK client-side to pass along a JWT which works fine, and my API is setup to handle token expiration, but I'm wondering what should happen if the user forcibly removes their token from local storage? The scenario in my mind:
Per the generated
README.md
, I configure my SDK client like this:My off-the-cuff idea would be to allow authentication keys to be set as functions which get invoked prior to firing off the XHR:
Other ideas that came to mind:
swagger-codegen
)superagent
request interceptorAny input on this is appreciated!