Skip to content

Commit

Permalink
update: root and apps
Browse files Browse the repository at this point in the history
Updated dependencies to latest
Use Auto Built Headless Chrome docker image
Declare mongoose-paginate related interfaces instead of using library
@types/mongoose-paginate caused warning message during TypeDoc generation
calculate at_hash for angular-oauth2-oidc 5.0.3 to work

show deprecation warning karma-runner/karma-jasmine#221
  • Loading branch information
revant committed Nov 13, 2018
1 parent 07acf33 commit cd11121
Show file tree
Hide file tree
Showing 30 changed files with 1,914 additions and 1,775 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
@@ -1,4 +1,4 @@
image: castlecraft/node-latest-headless-chrome:1.3
image: registry.gitlab.com/castlecraft/docker-craft/node-latest-headless-chrome:latest

services:
- docker:dind
Expand Down
3 changes: 1 addition & 2 deletions apps/authorization-server/README.md
Expand Up @@ -2,6 +2,5 @@

### More:

* [API](http://castlecraft.gitlab.io/building-blocks/api/authorization-server)
* [Developers](http://castlecraft.gitlab.io/building-blocks/authorization-server)
* [Developers](http://castlecraft.gitlab.io/building-blocks)
* [Users](https://gitlab.com/castlecraft/building-blocks/wikis/home)
86 changes: 43 additions & 43 deletions apps/authorization-server/package.json
Expand Up @@ -37,19 +37,19 @@
"translate": "ng xi18n --output-path i18n && xliffmerge --profile xliffmerge.json en af am ar bg bn bo bs ca cs da da-DK de el en-GB en-US es es-AR es-BO es-CL es-CO es-DO es-EC es-GT es-MX es-NI es-PE et fa fi fr fr-CA gu he hi hr hu is it ja km kn ko ku lo lt lv mk ml mr ms my nl no pl ps pt pt-BR quc ro ru rw si sk sl sq sr sr-SP sv sw ta te th tr uk ur uz vi zh zh-TW"
},
"dependencies": {
"@angular/animations": "^7.0.0",
"@angular/cdk": "^7.0.0",
"@angular/common": "^7.0.0",
"@angular/compiler": "^7.0.0",
"@angular/core": "^7.0.0",
"@angular/animations": "^7.0.3",
"@angular/cdk": "^7.0.3",
"@angular/common": "^7.0.3",
"@angular/compiler": "^7.0.3",
"@angular/core": "^7.0.3",
"@angular/flex-layout": "^7.0.0-beta.19",
"@angular/forms": "^7.0.0",
"@angular/http": "^7.0.0",
"@angular/material": "^7.0.0",
"@angular/platform-browser": "^7.0.0",
"@angular/platform-browser-dynamic": "^7.0.0",
"@angular/platform-server": "^7.0.0",
"@angular/router": "^7.0.0",
"@angular/forms": "^7.0.3",
"@angular/http": "^7.0.3",
"@angular/material": "^7.0.3",
"@angular/platform-browser": "^7.0.3",
"@angular/platform-browser-dynamic": "^7.0.3",
"@angular/platform-server": "^7.0.3",
"@angular/router": "^7.0.3",
"@nest-middlewares/passport": "^5.1.1",
"@nestjs/common": "^5.4.0",
"@nestjs/core": "^5.4.0",
Expand All @@ -59,25 +59,25 @@
"@nestjs/websockets": "^5.4.0",
"@nguniversal/express-engine": "^7.0.2",
"@nguniversal/module-map-ngfactory-loader": "^7.0.2",
"@types/passport-local": "^1.0.33",
"bull": "^3.4.8",
"class-transformer": "^0.1.10",
"class-transformer": "^0.2.0",
"class-validator": "^0.9.1",
"connect-mongo": "^2.0.1",
"cookie-parser": "^1.4.3",
"core-js": "^2.5.4",
"dotenv": "^6.1.0",
"express-rate-limit": "^3.2.1",
"express": "^4.16.4",
"express-rate-limit": "^3.3.2",
"express-session": "^1.15.6",
"hammerjs": "^2.0.8",
"hbs": "^4.0.1",
"helmet": "^3.14.0",
"joi": "^14.0.0",
"mongodb": "^3.1.8",
"mongoose": "^5.3.4",
"helmet": "^3.15.0",
"joi": "^14.0.6",
"mongodb": "^3.1.9",
"mongoose": "^5.3.11",
"mongoose-paginate": "^5.0.3",
"nestjs-ensureloggedin-guard": "^1.0.2",
"node-jose": "^1.0.0",
"node-jose": "^1.1.0",
"oauth2orize": "^1.11.0",
"oauth2orize-openid": "^0.4.0",
"passport": "^0.4.0",
Expand All @@ -88,7 +88,7 @@
"passport-oauth2-code": "^0.1.6",
"pem-jwk": "^1.5.1",
"point-of-view": "^2.0.0",
"qrcode": "^1.3.0",
"qrcode": "^1.3.2",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.3.3",
"rxjs-compat": "^6.3.3",
Expand All @@ -98,46 +98,46 @@
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.2",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "^7.0.0",
"@angular/language-service": "^7.0.0",
"@angular-devkit/build-angular": "~0.10.5",
"@angular/cli": "~7.0.5",
"@angular/compiler-cli": "^7.0.3",
"@angular/language-service": "^7.0.3",
"@nestjs/testing": "^5.4.0",
"@types/bull": "^3.3.20",
"@types/express": "^4.0.39",
"@types/jasmine": "~2.8.9",
"@types/jasminewd2": "~2.0.5",
"@types/jest": "23.3.5",
"@types/joi": "^13.6.1",
"@types/mongoose": "^5.2.19",
"@types/mongoose-paginate": "^5.0.6",
"@types/node": "^10.12.0",
"@types/bull": "^3.4.0",
"@types/express": "^4.16.0",
"@types/jasmine": "~2.8.11",
"@types/jasminewd2": "~2.0.6",
"@types/jest": "23.3.9",
"@types/joi": "^14.0.0",
"@types/mongoose": "^5.3.1",
"@types/node": "^10.12.6",
"@types/passport-local": "^1.0.33",
"@types/supertest": "^2.0.4",
"@types/yargs": "^12.0.1",
"codelyzer": "^4.5.0",
"concurrently": "^4.0.1",
"jasmine-core": "^3.2.1",
"jasmine-core": "^3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"jest": "^23.2.0",
"karma": "^3.0.0",
"karma": "^3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.3",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^1.3.1",
"karma-jasmine-html-reporter": "^1.4.0",
"ngx-i18nsupport": "^0.17.1",
"nodemon": "^1.18.4",
"prettier": "^1.11.1",
"nodemon": "^1.18.6",
"prettier": "^1.15.2",
"prettier-check": "^2.0.0",
"protractor": "^5.4.0",
"supertest": "^3.0.0",
"supertest-session": "^3.3.0",
"ts-jest": "^23.10.4",
"ts-loader": "^5.2.2",
"ts-loader": "^5.3.0",
"ts-node": "7.0.1",
"tsconfig-paths": "^3.1.1",
"tsconfig-paths": "^3.7.0",
"tslint": "^5.10.0",
"typescript": "~3.1.3",
"webpack": "4.22.0",
"typescript": "~3.1.6",
"webpack": "4.25.1",
"webpack-cli": "3.1.2",
"webpack-node-externals": "^1.6.0"
},
Expand Down
Expand Up @@ -22,6 +22,7 @@ export interface IDTokenClaims {
updated_at?: Date;
roles?: string[];
nonce?: string;
at_hash?: string;
}

export interface JWK {
Expand Down
Expand Up @@ -234,7 +234,13 @@ export class OAuth2orizeSetup implements OnModuleInit, OnApplicationBootstrap {
await this.tokenGrantService.grantToken(client, user, res, req, done);
},
async (client, user, req, done) => {
await this.idTokenGrantService.grantIDToken(client, user, req, done);
await this.idTokenGrantService.grantIDToken(
client,
user,
req,
done,
this.tokenGrantService.getAccessToken(),
);
},
),
);
Expand Down
Expand Up @@ -6,6 +6,7 @@ import { ServerSettingsService } from '../../../models/server-settings/server-se
import { ServerSettings } from '../../../models/interfaces/server-settings.interface';
import { JWKSNotFound } from '../../filters/exceptions';
import { ConfigService } from '../../../config/config.service';
import * as crypto from 'crypto';

@Injectable()
export class IDTokenGrantService {
Expand All @@ -17,7 +18,7 @@ export class IDTokenGrantService {
private readonly configService: ConfigService,
) {}

async grantIDToken(client, user, req, done) {
async grantIDToken(client, user, req, done, accessToken?: string) {
try {
if (!this.settings) this.settings = await this.settingsService.find();

Expand All @@ -35,6 +36,11 @@ export class IDTokenGrantService {
};

if (req.scope.includes('roles')) claims.roles = user.roles;
if (accessToken) {
// Thanks https://github.com/mozilla/fxa-oauth-server/pull/598/files
const atHash = this.generateTokenHash(accessToken);
claims.at_hash = atHash;
}

const jwks = await this.oidcKeyService.find();
const foundKey = jwks[0];
Expand All @@ -54,4 +60,24 @@ export class IDTokenGrantService {
done(error, null);
}
}

generateTokenHash(accessTokenBuf) {
const hash = this.encryptHash(accessTokenBuf.toString('ascii'));
return this.base64URLEncode(hash.slice(0, hash.length / 2));
}

base64URLEncode(buf) {
return buf
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
}

encryptHash(hash) {
const value = Buffer.from(hash, 'ascii');
const sha = crypto.createHash('sha256');
sha.update(value);
return sha.digest();
}
}
Expand Up @@ -5,6 +5,8 @@ import { ClientService } from '../../../models/client/client.service';

@Injectable()
export class TokenGrantService {
accessToken: string;

constructor(
private readonly userService: UserService,
private readonly clientService: ClientService,
Expand Down Expand Up @@ -32,9 +34,14 @@ export class TokenGrantService {
scope,
false,
);
this.accessToken = bearerToken.accessToken;
return done(null, bearerToken.accessToken, extraParams);
} catch (error) {
return done(error);
}
}

getAccessToken() {
return this.accessToken;
}
}
@@ -1,8 +1,8 @@
import { PaginateModel } from 'mongoose';
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { CLIENT } from './client.schema';
import { Client } from '../interfaces/client.interface';
import { PaginateModel } from '../../typings/mongoose';

@Injectable()
export class ClientService {
Expand Down
@@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common';
import { PaginateModel } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { ROLE } from './role.schema';
import { Role } from '../interfaces/role.interface';
import { invalidRoleException } from '../../auth/filters/exceptions';
import { PaginateModel } from '../../typings/mongoose';

@Injectable()
export class RoleService {
Expand Down
@@ -1,9 +1,9 @@
import { Injectable } from '@nestjs/common';
import { PaginateModel } from 'mongoose';
import { SCOPE } from './scope.schema';
import { InjectModel } from '@nestjs/mongoose';
import { Scope } from '../interfaces/scope.interface';
import { invalidScopeException } from '../../auth/filters/exceptions';
import { PaginateModel } from '../../typings/mongoose';

@Injectable()
export class ScopeService {
Expand Down
@@ -1,5 +1,5 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { Model, PaginateModel } from 'mongoose';
import { Model } from 'mongoose';
import {
USER_DELETED,
USER_NOT_ADMINISTRATOR,
Expand All @@ -19,6 +19,7 @@ import { AUTH_DATA } from '../auth-data/auth-data.schema';
import { User } from '../interfaces/user.interface';
import { AuthData } from '../interfaces/auth-data.interface';
import { ADMINISTRATOR } from '../../constants/roles';
import { PaginateModel } from '../../typings/mongoose';

@Injectable()
export class UserService {
Expand Down
43 changes: 43 additions & 0 deletions apps/authorization-server/src/server/typings/mongoose.d.ts
@@ -0,0 +1,43 @@
import { Model, Schema, Document } from 'mongoose';

export interface PaginateOptions {
select?: object | string;
sort?: object | string;
populate?: Array<object> | Array<string> | object | string;
lean?: boolean;
leanWithId?: boolean;
offset?: number;
page?: number;
limit?: number;
}

export interface PaginateResult<T> {
docs: Array<T>;
total: number;
limit: number;
page?: number;
pages?: number;
offset?: number;
}

export interface PaginateModel<T extends Document> extends Model<T> {
paginate(
query?: object,
options?: PaginateOptions,
callback?: (err: any, result: PaginateResult<T>) => void,
): Promise<PaginateResult<T>>;
}

export function model<T extends Document>(
name: string,
schema?: Schema,
collection?: string,
skipInit?: boolean,
): PaginateModel<T>;

export function model<T extends Document, U extends PaginateModel<T>>(
name: string,
schema?: Schema,
collection?: string,
skipInit?: boolean,
): U;

0 comments on commit cd11121

Please sign in to comment.