Skip to content
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

Remove typings, and update type definitions for Hapi.js #1

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ This app uses `npm` to provision it dependencies.
* `git clone` the `AppAuthJS` library and go to the root folder of
the project containing `package.json` file.
* `npm install` to install all the dev and project dependencies.
* `typings install` to install all TypeScript definitions.

Thats it! You are now ready to start working on `AppAuthJS`.

Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
"author": "rahulrav@google.com",
"license": "MIT",
"devDependencies": {
"@types/es6-promise": "0.0.32",
"@types/form-data": "0.0.33",
"@types/hapi": "^16.1.2",
"@types/jasmine": "^2.5.47",
"@types/jquery": "^2.0.45",
"@types/node": "^7.0.22",
"@types/opener": "^1.4.0",
"@types/react": "^15.0.24",
"@types/react-dom": "^15.5.0",
"@types/request": "0.0.43",
"browserify": "^13.1.0",
"clang-format": "^1.0.49",
"google-closure-compiler": "^20160911.0.0",
Expand All @@ -45,7 +55,6 @@
"karma-browserify": "^5.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-jasmine": "^1.1.0",
"typescript": "^2.2.2",
"typings": "^2.1.0",
"watchify": "^3.7.0"
},
Expand All @@ -54,6 +63,6 @@
"hapi": "^16.1.0",
"opener": "^1.4.2",
"request": "^2.79.0",
"typescript": "^2.3.1"
"typescript": "^2.3.3"
}
}
64 changes: 32 additions & 32 deletions src/node_support/node_request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*/

import opener = require('opener');
import Hapi = require('hapi');
import { Request, ServerConnectionOptions, Server, ServerConnection, ReplyNoContinue } from 'hapi';
import EventEmitter = require('events');
import {BasicQueryStringUtils, QueryStringUtils} from '../query_string_utils';
import {AuthorizationRequest, AuthorizationRequestJson} from '../authorization_request';
import {AuthorizationRequestHandler, AuthorizationRequestResponse, BUILT_IN_PARAMETERS, generateRandom} from '../authorization_request_handler';
import {AuthorizationError, AuthorizationResponse, AuthorizationResponseJson} from '../authorization_response'
import {AuthorizationServiceConfiguration, AuthorizationServiceConfigurationJson} from '../authorization_service_configuration';
import {log} from '../logger';
import { BasicQueryStringUtils, QueryStringUtils } from '../query_string_utils';
import { AuthorizationRequest, AuthorizationRequestJson } from '../authorization_request';
import { AuthorizationRequestHandler, AuthorizationRequestResponse, BUILT_IN_PARAMETERS, generateRandom } from '../authorization_request_handler';
import { AuthorizationError, AuthorizationResponse, AuthorizationResponseJson, AuthorizationErrorJson } from '../authorization_response'
import { AuthorizationServiceConfiguration, AuthorizationServiceConfigurationJson } from '../authorization_service_configuration';
import { log } from '../logger';

class ServerEventsEmitter extends EventEmitter {
static ON_UNABLE_TO_START = 'unable_to_start';
Expand All @@ -30,7 +30,7 @@ class ServerEventsEmitter extends EventEmitter {
export class NodeBasedHandler extends AuthorizationRequestHandler {
httpServerPort: number;
// the handle to the current authorization request
authorizationPromise: Promise<AuthorizationRequestResponse|null>|null;
authorizationPromise: Promise<AuthorizationRequestResponse | null> | null;

constructor(httpServerPort?: number, utils?: QueryStringUtils) {
super(utils || new BasicQueryStringUtils());
Expand All @@ -40,11 +40,11 @@ export class NodeBasedHandler extends AuthorizationRequestHandler {
}

performAuthorizationRequest(
configuration: AuthorizationServiceConfiguration, request: AuthorizationRequest) {
configuration: AuthorizationServiceConfiguration, request: AuthorizationRequest) {
// use opener to launch a web browser and start the authorization flow.
// start a web server to handle the authorization response.
const server = new Hapi.Server();
server.connection(<Hapi.IServerConnectionOptions>{port: this.httpServerPort});
const server = new Server();
server.connection(<ServerConnectionOptions>{ port: this.httpServerPort });
const emitter = new ServerEventsEmitter();

this.authorizationPromise = new Promise<AuthorizationRequestResponse>((resolve, reject) => {
Expand All @@ -62,14 +62,14 @@ export class NodeBasedHandler extends AuthorizationRequestHandler {
server.route({
method: 'GET',
path: '/',
handler: (hapiRequest: Hapi.Request, hapiResponse: Hapi.IReply) => {
let queryParams = hapiRequest.query;
let state: string|undefined = queryParams['state'];
let code: string|undefined = queryParams['code'];
let error: string|undefined = queryParams['error'];
handler: (hapiRequest: Request, hapiResponse: ReplyNoContinue) => {
let queryParams = hapiRequest.query as (AuthorizationResponseJson & AuthorizationErrorJson);
let state = queryParams['state'];
let code = queryParams['code'];
let error = queryParams['error'];
log('Handling Authorization Request ', queryParams, state, code, error);
let authorizationResponse: AuthorizationResponse|null = null;
let authorizationError: AuthorizationError|null = null;
let authorizationResponse: AuthorizationResponse | null = null;
let authorizationError: AuthorizationError | null = null;
if (error) {
// get additional optional info.
let errorUri = queryParams['error_uri'];
Expand All @@ -79,31 +79,31 @@ export class NodeBasedHandler extends AuthorizationRequestHandler {
authorizationResponse = new AuthorizationResponse(code!, state!);
}
let completeResponse = {
request: request,
response: authorizationResponse,
error: authorizationError
} as AuthorizationRequestResponse;
request: request,
response: authorizationResponse,
error: authorizationError
} as AuthorizationRequestResponse;
emitter.emit(ServerEventsEmitter.ON_AUTHORIZATION_RESPONSE, completeResponse);
hapiResponse('Close your browser to continue');
server.stop();
}
});

server.start()
.then(() => {
let url = this.buildRequestUrl(configuration, request);
log('Making a request to ', request, url);
opener(url);
})
.catch(error => {
log('Something bad happened ', error);
});
.then(() => {
let url = this.buildRequestUrl(configuration, request);
log('Making a request to ', request, url);
opener(url);
})
.catch(error => {
log('Something bad happened ', error);
});
}

protected completeAuthorizationRequest(): Promise<AuthorizationRequestResponse|null> {
protected completeAuthorizationRequest(): Promise<AuthorizationRequestResponse | null> {
if (!this.authorizationPromise) {
return Promise.reject(
'No pending authorization request. Call performAuthorizationRequest() ?');
'No pending authorization request. Call performAuthorizationRequest() ?');
}

return this.authorizationPromise;
Expand Down
2 changes: 1 addition & 1 deletion src/token_response_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Token Response tests', () => {
'bearer',
1 /* issued at */,
1000 /* expires in*/
);
);

expect(response).not.toBeNull();
expect(response.accessToken).toBe(accessToken);
Expand Down
19 changes: 0 additions & 19 deletions typings.json

This file was deleted.