Skip to content

Commit 9f1fdf5

Browse files
Adding ClientCredential service, some fixes.
1 parent 51ab66f commit 9f1fdf5

11 files changed

+48
-8
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"typescript": "^2.2.1"
3131
},
3232
"dependencies": {
33-
"randomstring": "^1.1.5"
33+
"inversify": "^3.1.0",
34+
"randomstring": "^1.1.5",
35+
"reflect-metadata": "^0.1.10"
3436
}
3537
}

source/Flows/BaseFlow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export abstract class BaseFlow implements IFlow {
1010
* @param type Represents the type of the flow processor.
1111
*/
1212
constructor(type:string) {
13-
this._type = type;
13+
this._type = type;
1414
}
1515

1616
private _type:string;
@@ -29,5 +29,5 @@ export abstract class BaseFlow implements IFlow {
2929
* Execute the flow and handle it with the given handler.
3030
* @param handler Represents the handler for the flow.
3131
*/
32-
public abstract execute(handler:IFlowHandler):void;
32+
public abstract execute(handler:IFlowHandler):Promise<void>;
3333
}

source/Flows/IFlow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export interface IFlow {
77
/**
88
* Execute the flow and handle it with the given handler.
99
*/
10-
execute(handler:IFlowHandler):Promise<void>
10+
execute(handler:IFlowHandler):Promise<void>;
1111
}

source/Flows/ScopeBaseFlow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export abstract class ScopeBaseFlow extends BaseFlow {
2828
* Execute the flow and handle it with the given handler.
2929
* @param handler Represents the handler for the flow.
3030
*/
31-
public abstract execute(handler:IFlowHandler):void;
31+
public abstract execute(handler:IFlowHandler):Promise<void>;
3232
}

source/OAuthContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ export class OAuthContext {
2525
this._configuration.refreshTokenExpirationTime = null;
2626
this._configuration.authorizationCodeExpirationTime = 30;
2727
this._configuration.mustGenerateRefreshToken = false;
28+
this._configuration.tokenLength = 20;
2829
}
2930
}

source/OAuthContextConfiguration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ export class OAuthContextConfiguration {
2222
* Get or set a boolean value specifying if the token generation process must create an refresh token;
2323
*/
2424
public mustGenerateRefreshToken:boolean;
25+
26+
/**
27+
* Get or set the length of the generated tokens.
28+
*/
29+
public tokenLength:number;
2530
}

source/Services/IClientService.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Represents a client service.
3+
*/
4+
export interface ICLientService {
5+
/**
6+
* Return a boolean value specifying if a client exists with the given id.
7+
* @param clientId Represents the id of the client to look for.
8+
*/
9+
existsClient(clientId:string):Promise<boolean>;
10+
11+
/**
12+
* Return a boolean value specifying if the given credentials are valis.
13+
* @param clientId Represents the id of the client to authenticate.
14+
* @param clientSecret Represents the secret of the client to authenticate.
15+
*/
16+
validateCredentials(clientId:string, clientSecret:string):Promise<boolean>;
17+
}

source/Services/IUserService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export interface IUserService {
77
* @param username Represents the user name.
88
* @param password Represents the user password.
99
*/
10-
validateCredential(username:string, password:string):Promise<boolean>;
10+
validateCredentials(username:string, password:string):Promise<boolean>;
1111
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
import randomstring = require("randomstring")
2+
13
import { ITokenGenerationService } from './ITokenGenerationService'
4+
import { OAuthContext } from "../OAuthContext";
25

36
/**
47
* Represents a token generation service to generate tokens.
58
*/
69
export class TokenGenerationService implements ITokenGenerationService {
10+
11+
private _oAuthContext:OAuthContext;
12+
13+
/**
14+
* Create a new instance of the token generation service.
15+
* @param oAuthContext Represents the OAuth context that containing the default configurations for common objects.
16+
*/
17+
constructor(oAuthContext:OAuthContext) {
18+
this._oAuthContext = oAuthContext;
19+
}
720

821
/**
922
* Get a new ramdom token value;
1023
*/
1124
public async getTokenValue():Promise<string> {
12-
return 'sdhbfhksbdjkfbsbgbsjfkabghkbf';
25+
return randomstring.generate(this._oAuthContext.configuration.tokenLength | 20);
1326
}
1427
}

source/Services/TokenService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export class TokenService implements ITokenService {
1717
/**
1818
* Create a new instance of the token service.
1919
* @param tokenRepository Represents the token repository to consult and persist tokens.
20+
* @param tokenGenerationService Represents the token generation service to generate tokens values.
21+
* @param oAuthContext Represents the OAuth context that containing the default configurations for common objects.
2022
*/
2123
constructor(tokenRepository:ITokenRepository
2224
,tokenGenerationService:ITokenGenerationService

source/Services/UserService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class UserService implements IUserService {
2222
* @param username Represents the user name.
2323
* @param password Represents the user password.
2424
*/
25-
public async validateCredential(username: string, password: string): Promise<boolean> {
25+
public async validateCredentials(username: string, password: string): Promise<boolean> {
2626

2727
let user:User = await this._userRepository.getByName(username);
2828

0 commit comments

Comments
 (0)