-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[typescript-angular2] Allow lazy oauth token refresh (#6486) #6496
[typescript-angular2] Allow lazy oauth token refresh (#6486) #6496
Conversation
@alexrashed I'll restart the CI jobs later to give it another try. cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx for review. |
@alexrashed when you've time, please rebase on the latest master to resolve the merge conflicts. |
61a56ee
to
edb367a
Compare
Again the automated Travis build failed, but the one coupled to my forked repo succeeded: https://travis-ci.org/alexrashed/swagger-codegen/builds/280310264 |
@alexrashed no worry. I'll restart the Travis job. cc @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx for review. |
Thanks for the PR, it looks really promising. I'm going to have to check it out and try locally though. Looking forward to using this! |
@sebastianhaas I looked over this and it seems good. I also haven't tried it locally but I'll try to verify as well with you. from the other PR he made we had a convo about it as I thought it wasn't needed but this changes only brings benefit to the client so I backed down :) |
edb367a
to
0c657d3
Compare
- Startover with a new branch after pr swagger-api#6493 was created on the wrong branch - Handover authentication scheme name as well as the scopes to the accessToken function in the Configuration class - accessToken returns an Observable to allow a lazy refresh of the accessToken
0c657d3
to
69fc765
Compare
I rebased the changes once again and also added a pom file to automatically build the Typescript Angular 4.3 (HttpClient) changes with the samples profile. |
This should work with lower level angular right? I didn't think there was
anything specific to 4.3
…On Wed, Oct 11, 2017, 3:18 AM Alexander Rashed ***@***.***> wrote:
I rebased the changes once again and also added a pom file to
automatically build the Typescript Angular 4.3 (HttpClient) changes with
the samples profile.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6496 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtUJNWIeM9Z9EOQ_kr7LJJMlENWLKks5srGu_gaJpZM4PWhVB>
.
|
Of course. But recent changes on the master differ in handling the header depending on the new option for using the new HttpClient. So I rebased my changes, adopted them to correctly set the header fields depending on the option and also added a pom file for the previous changes for HttpClient (which weren't done by me, but I realized that the sample client is not built yet when executing the sample maven profile). |
Okay thanks and good catch
…On Wed, Oct 11, 2017, 7:22 AM Alexander Rashed ***@***.***> wrote:
Of course. But recent changes on the master differ in handling the header
depending on the new option for using the new HttpClient. So I rebased my
changes, adopted them to correctly set the header fields depending on the
option and also added a pom file for the previous changes for HttpClient
(which weren't done by me, but I realized that the sample client is not
built yet when executing the sample maven profile).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6496 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtVlH8OGPJo9O9dSWloVI2e8aZVw0ks5srKT2gaJpZM4PWhVB>
.
|
This seems rather complicated: Why must we extend the code generator, when the HttpClient makes it easy to add a token to all requests by means of an HttpInterceptor? My app does not even use the accessToken feature of the code generator, but simply declare
and register it with
It is also worth noting that the above solution supports repeated subscription on the Observable. For instance, That is, idiomatic functional reactive programming is only possible if access tokens are evaluated upon subscription rather than being baked into Observables. This is trivial to achieve with an HttpInterceptor, and hard to achieve in the code generator. I'd therefore prefer Configuration.accessToken to be deprecated rather than extending its implementation once again to cover more (but not yet all) usecases. |
Interceptor is a nice pattern / feature which solves the less complex configurations fairly elegant. But an interceptor can't access some data needed for more advanced OAuth swagger configs, f.e. the different scopes for each method. Also the token isn't static if you assign it a function. But I do agree that it gets rather complicated, but I would question the importance of supporting the old http client in a new release (without having a closer look at the PR / issue threads). |
Adrian I'm with you here but Alex made fine arguments for this feature at
the time so I gave in. I would love for @tufu @sebastianhaas to chime in on
deprecation of the access token as well since 4.3 let's you handle all
this.
…On Thu, Oct 12, 2017, 6:06 PM Alexander Rashed ***@***.***> wrote:
Also the token isn't static if you assign it a function.
This function is evaluated for every request and therefore is equally
powerful as the interceptor in terms of the execution flow.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6496 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtX_5rJUmiTAWCv84ZNeLRiq46Gioks5sro10gaJpZM4PWhVB>
.
|
@alexrashed: The current PR does not support variable scopes per method either, does it? And the interceptor can inspect the entire request, and pick different scopes accordingly. This why I'd make the interceptor part of the application, so developers can easily modify it to suit their needs.
I don't think you understood the point I was making. Yes, every invocation of the generated api service method gets a fresh token, but in both Http and HttpClient, a request is sent whenever the returned Observable is subscribed to. This can easily happen more than once when employing RXJS operators. Consider the following code:
Here, an Observable is created once, but a request is sent every 5 minutes. |
The PR does support variable scopes per method. It's pretty much the same as implemented for the typescript-fetch client with PR #6130 (but with observables). The latter however is true, the observable is only created once. |
Ah, I didn't notice the arguments added to |
Since there hasn't been any progress and this PR is heavily outdated, I'm closing it. |
Unfortunately it was a pain to update the previous PR / feature-branch, so here's a fresh branch / PR for ticket #6486 replacing PR #6493.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for breaking (non-backward compatible) changes.Description of the PR
Fixes #6486.
Replaces #6493.
accessToken
function in theConfiguration
as seen in [Typescript-Fetch] Support additionalproperties, Enum, Auth and more. #6130accessToken
function now returns anObservable<string>
(allows lazy renewal using therefreshToken
)