1414 * limitations under the License.
1515 */
1616
17+ import { IncomingHttpHeaders } from 'http' ;
1718import { BaseService } from 'ibm-cloud-sdk-core' ;
1819import url = require( 'url' ) ;
1920
2021class AuthorizationV1 extends BaseService {
2122 static URL : string = 'https://stream.watsonplatform.net/authorization/api' ;
22- name ;
23- serviceVersion ;
23+ name : string ; // set by prototype to 'authorization'
24+ serviceVersion : string ; // set by prototype to 'v1'
25+ // tslint:disable-next-line:variable-name
26+ target_url ?: string ;
2427
2528 /**
2629 * Authorization Service
@@ -34,9 +37,9 @@ class AuthorizationV1 extends BaseService {
3437 * @param {String } [options.url] url of the service for which auth tokens are being generated
3538 * @constructor
3639 */
37- constructor ( options ) {
40+ constructor ( options : AuthorizationV1 . Options ) {
3841 super ( options ) ;
39- this [ ' target_url' ] = options . url ;
42+ this . target_url = options . url ;
4043 // replace the url to always point to /authorization/api
4144 const hostname = url . parse ( this . _options . url ) ;
4245 hostname . pathname = '/authorization/api' ;
@@ -51,10 +54,10 @@ class AuthorizationV1 extends BaseService {
5154 * @param {String } [options.url] defaults to url supplied to constructor (if any)
5255 * @param {Function(err, token) } callback - called with a %-encoded token if CF
5356 */
54- getToken ( params , callback ) {
57+ getToken ( params : AuthorizationV1 . GetTokenParams | AuthorizationV1 . GetTokenCallback , callback ?: AuthorizationV1 . GetTokenCallback ) {
5558 if ( typeof params === 'function' ) {
5659 callback = params ;
57- params = { url : this [ ' target_url' ] } ;
60+ params = { url : this . target_url } ;
5861 }
5962
6063 // if the service is an RC instance, return an IAM access token
@@ -83,4 +86,33 @@ class AuthorizationV1 extends BaseService {
8386AuthorizationV1 . prototype . name = 'authorization' ;
8487AuthorizationV1 . prototype . serviceVersion = 'v1' ;
8588
89+ /*************************
90+ * interfaces
91+ ************************/
92+
93+ namespace AuthorizationV1 {
94+ /** Options for the AuthorizationV1 constructor */
95+ export type Options = {
96+ username : string ;
97+ password : string ;
98+ url ?: string ;
99+ }
100+
101+ export interface GetTokenResponse {
102+ result : string ;
103+ data : string ; // for compatibility
104+ status : number ;
105+ statusText : string ;
106+ headers : IncomingHttpHeaders ;
107+ }
108+
109+ /** The callback for the getToken request. */
110+ export type GetTokenCallback = ( error : any , token ?: string , response ?: GetTokenResponse ) => void ;
111+
112+ /** Parameters for the `getToken` operation */
113+ export interface GetTokenParams {
114+ url ?: string ;
115+ }
116+ }
117+
86118export = AuthorizationV1 ;
0 commit comments