-
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 (async access_token function) #6486
Comments
Fix invalid auth header zip function (needs to return the resulting header for the next observable).
- Add missing rxjs operators - Changed project name in package.json (seems like it's been overlooked after copy/pasting ng2 project) - Update ts-ng2 & ts-ng4 petstore code (seems this hasn't been done the last time)
- Generate ts-ng2 security client (also contains some previous changes)
- Fix swagger annotations version in jaxrs-cxf-cdi pom after 2.0.0-rc1 release (maven doesn't know anything about rc versions - used 1.99 as a workaround) - Re-generated the jaxrs-cxf-cdi client
Hey you can do this without making changes! I'm sorry I missed this but if you do this in angular2
this will allow you anywher ein the code to inject the configuration object and change it at any point in time! |
This way I can easily exchange the configuration, but it doesn't really help me with updating my accessToken in case of a request (and an expired token), or am I wrong? |
swagger-codegen/samples/client/petstore/typescript-angular-v2/npm/configuration.ts Lines 10 to 26 in 8067612
I am assuming you are storing the accessToken as a part of the configuration object. If this is so you can easily invalidate it with a AuthService you make in your Angular app by injecting Configuration and overwriting it with undefined and updating it by overwriting it with the new value. What will happen is that value will ALWAYS be used since you've provided a non multi value in the providers. So that means all of the used Services that inject Configuration will have the same reference to that and anytime a request is made will use the new AccessToken. I use this strategy for updating Username//Password when users login. |
The key is that it is all the same object as long as you setup your services in AppModule as they should be. |
I get what you mean, but my problem is not that I can't statically manage the accessToken, my problem of the lazy update of the accessToken still remains. I don't think I can implement this in a proper manner by just exchanging the Configuration in the CDI context. If it would be possible, could you give me a more advanced example? |
- 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
As of Late in Angular 4, you can assign interceptors to every request. Event if not using angular 4 there are multiple libraries that do this. https://angular.io/api/common/http/HttpInterceptor You could easily have an interceptor that checks if a token is valid for a request and try to auto refresh it before you return the request to be made. I've actually done this is my code for our in house SSO setup. |
Yeah, I already evaluated that approach too. And I know that there are several possible ways to implement my requirement. |
- 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
- 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
- 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
I closed the PR, since there hasn't been any progress and it's heavily outdated. Therefore I'm closing this ticket too. |
Description
In case of an OAuth2 implicit flow the current implementation of the
Configuration
class allows theaccessToken
to either be a string or a function returning a string (directly). In order to allow a lazy update of the (already expired)access_token
using the (still valid)refresh_token
the function should get the name of the authorization scheme as well as the necessary scopes and should return anObservable<string>
.This would allow an asynchronous implementation of the
accessToken
function where the auth server can be requested for a new token.Swagger-codegen version
2.3.0-SNAPSHOT
Command line used for generation
swagger-codegen-maven-plugin in version 2.3.0-SNAPSHOT for typescript-angular with ngVersion=4
Steps to reproduce
Try to create a Configuration object which lazily refreshes the
access_token
(when the access_token has expired, but the refresh_token is still valid).Related issues/PRs
I commented on a PR for the typescript-fetch client suggesting this feature a few weeks ago (this time I mean the angular2 client): #6130 (comment)
This PR also contains the new parameters for the
accessToken
function for the Typescript-Flow client (but does not return anObservable<string>
): Configuration class changes in PR 6130Suggest a fix/enhancement
Observable<string>
access_token
functionI'm working on a PR right now, I just want to make sure that the feature would be accepted. :)
The text was updated successfully, but these errors were encountered: