-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript-angular2] Allow lazy oauth token refresh (#6486)
- Startover with a new branch after pr #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
- Loading branch information
1 parent
28a3206
commit edb367a
Showing
52 changed files
with
2,217 additions
and
2,959 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
samples/client/petstore-security-test/typescript-angular/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
wwwroot/*.js | ||
node_modules | ||
typings | ||
dist |
2 changes: 1 addition & 1 deletion
2
samples/client/petstore-security-test/typescript-angular/.swagger-codegen/VERSION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.2.3 | ||
2.3.0-SNAPSHOT |
24 changes: 19 additions & 5 deletions
24
samples/client/petstore-security-test/typescript-angular/api.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import * as api from './api/api'; | ||
import * as angular from 'angular'; | ||
import { NgModule, ModuleWithProviders } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { HttpModule } from '@angular/http'; | ||
import { Configuration } from './configuration'; | ||
|
||
const apiModule = angular.module('api', []) | ||
.service('FakeApi', api.FakeApi) | ||
import { FakeService } from './api/fake.service'; | ||
|
||
export default apiModule; | ||
@NgModule({ | ||
imports: [ CommonModule, HttpModule ], | ||
declarations: [], | ||
exports: [], | ||
providers: [ FakeService ] | ||
}) | ||
export class ApiModule { | ||
public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { | ||
return { | ||
ngModule: ApiModule, | ||
providers: [ {provide: Configuration, useFactory: configurationFactory}] | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
samples/client/petstore-security-test/typescript-angular/api/api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './FakeApi'; | ||
import { FakeApi } from './FakeApi'; | ||
export const APIS = [FakeApi]; | ||
export * from './fake.service'; | ||
import { FakeService } from './fake.service'; | ||
export const APIS = [FakeService]; |
160 changes: 160 additions & 0 deletions
160
samples/client/petstore-security-test/typescript-angular/api/fake.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/** | ||
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r | ||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- | ||
* | ||
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r | ||
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r | ||
* | ||
* NOTE: This class is auto generated by the swagger code generator program. | ||
* https://github.com/swagger-api/swagger-codegen.git | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
/* tslint:disable:no-unused-variable member-ordering */ | ||
|
||
import { Inject, Injectable, Optional } from '@angular/core'; | ||
import { Http, Headers, URLSearchParams } from '@angular/http'; | ||
import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; | ||
import { Response, ResponseContentType } from '@angular/http'; | ||
|
||
import { Observable } from 'rxjs/Observable'; | ||
import '../rxjs-operators'; | ||
|
||
|
||
import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; | ||
import { Configuration } from '../configuration'; | ||
import { CustomQueryEncoderHelper } from '../encoder'; | ||
|
||
|
||
@Injectable() | ||
export class FakeService { | ||
|
||
protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; | ||
public defaultHeaders: Headers = new Headers(); | ||
public configuration: Configuration = new Configuration(); | ||
constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { | ||
if (basePath) { | ||
this.basePath = basePath; | ||
} | ||
if (configuration) { | ||
this.configuration = configuration; | ||
this.basePath = basePath || configuration.basePath || this.basePath; | ||
} | ||
} | ||
/** | ||
* | ||
* Extends object by coping non-existing properties. | ||
* @param objA object to be extended | ||
* @param objB source object | ||
*/ | ||
private extendObj<T1,T2>(objA: T1, objB: T2) { | ||
for(let key in objB){ | ||
if(objB.hasOwnProperty(key)){ | ||
(objA as any)[key] = (objB as any)[key]; | ||
} | ||
} | ||
return <T1&T2>objA; | ||
} | ||
/** | ||
* @param consumes string[] mime-types | ||
* @return true: consumes contains 'multipart/form-data', false: otherwise | ||
*/ | ||
private canConsumeForm(consumes: string[]): boolean { | ||
const form = 'multipart/form-data'; | ||
for (let consume of consumes) { | ||
if (form === consume) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
public isJsonMime(mime: string): boolean { | ||
const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); | ||
return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); | ||
} | ||
/** | ||
* | ||
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r | ||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r | ||
*/ | ||
public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable<{}> { | ||
return this.testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r, extraHttpRequestParams) | ||
.map((response: Response) => { | ||
if (response.status === 204) { | ||
return undefined; | ||
} else { | ||
return response.json() || {}; | ||
} | ||
}); | ||
} | ||
/** | ||
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r | ||
* | ||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r | ||
*/ | ||
public testCodeInjectEndRnNRWithHttpInfo(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable<Response> { | ||
const path = this.basePath + '/fake'; | ||
let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); | ||
let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 | ||
// to determine the Content-Type header | ||
let consumes: string[] = [ | ||
'application/json', | ||
'*_/ =end -- ' | ||
]; | ||
if (consumes != null && consumes.length > 0) { | ||
headersObservable = headersObservable.do((headers: Headers) => | ||
headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";"))); | ||
} | ||
|
||
let canConsumeForm = this.canConsumeForm(consumes); | ||
let useForm = false; | ||
let formParams = new (useForm ? FormData : URLSearchParams as any)() as { | ||
set(param: string, value: any): void; | ||
}; | ||
|
||
// to determine the Accept header | ||
let produces: string[] = [ | ||
'application/json', | ||
'*_/ =end -- ' | ||
]; | ||
|
||
if (produces != null && produces.length > 0) { | ||
headersObservable = headersObservable.do((headers: Headers) => | ||
headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';'))); | ||
} | ||
|
||
|
||
if (test code inject * ' " =end rn n r !== undefined) { | ||
formParams.set('test code inject */ ' " =end -- \r\n \n \r', <any>test code inject * ' " =end rn n r); | ||
} | ||
|
||
let requestOptionsObservable = headersObservable.map((headers: Headers) => { | ||
let requestOptions: RequestOptionsArgs = new RequestOptions({ | ||
method: RequestMethod.Put, | ||
headers: headers, | ||
body: formParams.toString(), | ||
search: queryParameters, | ||
withCredentials:this.configuration.withCredentials | ||
}); | ||
// https://github.com/swagger-api/swagger-codegen/issues/4037 | ||
if (extraHttpRequestParams) { | ||
requestOptions = (<any>Object).assign(requestOptions, extraHttpRequestParams); | ||
} | ||
|
||
return requestOptions; | ||
}); | ||
|
||
return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); | ||
} | ||
|
||
} |
Oops, something went wrong.