File tree Expand file tree Collapse file tree 11 files changed +48
-8
lines changed Expand file tree Collapse file tree 11 files changed +48
-8
lines changed Original file line number Diff line number Diff line change 30
30
"typescript" : " ^2.2.1"
31
31
},
32
32
"dependencies" : {
33
- "randomstring" : " ^1.1.5"
33
+ "inversify" : " ^3.1.0" ,
34
+ "randomstring" : " ^1.1.5" ,
35
+ "reflect-metadata" : " ^0.1.10"
34
36
}
35
37
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ export abstract class BaseFlow implements IFlow {
10
10
* @param type Represents the type of the flow processor.
11
11
*/
12
12
constructor ( type :string ) {
13
- this . _type = type ;
13
+ this . _type = type ;
14
14
}
15
15
16
16
private _type :string ;
@@ -29,5 +29,5 @@ export abstract class BaseFlow implements IFlow {
29
29
* Execute the flow and handle it with the given handler.
30
30
* @param handler Represents the handler for the flow.
31
31
*/
32
- public abstract execute ( handler :IFlowHandler ) :void ;
32
+ public abstract execute ( handler :IFlowHandler ) :Promise < void > ;
33
33
}
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ export interface IFlow {
7
7
/**
8
8
* Execute the flow and handle it with the given handler.
9
9
*/
10
- execute ( handler :IFlowHandler ) :Promise < void >
10
+ execute ( handler :IFlowHandler ) :Promise < void > ;
11
11
}
Original file line number Diff line number Diff line change @@ -28,5 +28,5 @@ export abstract class ScopeBaseFlow extends BaseFlow {
28
28
* Execute the flow and handle it with the given handler.
29
29
* @param handler Represents the handler for the flow.
30
30
*/
31
- public abstract execute ( handler :IFlowHandler ) :void ;
31
+ public abstract execute ( handler :IFlowHandler ) :Promise < void > ;
32
32
}
Original file line number Diff line number Diff line change @@ -25,5 +25,6 @@ export class OAuthContext {
25
25
this . _configuration . refreshTokenExpirationTime = null ;
26
26
this . _configuration . authorizationCodeExpirationTime = 30 ;
27
27
this . _configuration . mustGenerateRefreshToken = false ;
28
+ this . _configuration . tokenLength = 20 ;
28
29
}
29
30
}
Original file line number Diff line number Diff line change @@ -22,4 +22,9 @@ export class OAuthContextConfiguration {
22
22
* Get or set a boolean value specifying if the token generation process must create an refresh token;
23
23
*/
24
24
public mustGenerateRefreshToken :boolean ;
25
+
26
+ /**
27
+ * Get or set the length of the generated tokens.
28
+ */
29
+ public tokenLength :number ;
25
30
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -7,5 +7,5 @@ export interface IUserService {
7
7
* @param username Represents the user name.
8
8
* @param password Represents the user password.
9
9
*/
10
- validateCredential ( username :string , password :string ) :Promise < boolean > ;
10
+ validateCredentials ( username :string , password :string ) :Promise < boolean > ;
11
11
}
Original file line number Diff line number Diff line change
1
+ import randomstring = require( "randomstring" )
2
+
1
3
import { ITokenGenerationService } from './ITokenGenerationService'
4
+ import { OAuthContext } from "../OAuthContext" ;
2
5
3
6
/**
4
7
* Represents a token generation service to generate tokens.
5
8
*/
6
9
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
+ }
7
20
8
21
/**
9
22
* Get a new ramdom token value;
10
23
*/
11
24
public async getTokenValue ( ) :Promise < string > {
12
- return 'sdhbfhksbdjkfbsbgbsjfkabghkbf' ;
25
+ return randomstring . generate ( this . _oAuthContext . configuration . tokenLength | 20 ) ;
13
26
}
14
27
}
Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ export class TokenService implements ITokenService {
17
17
/**
18
18
* Create a new instance of the token service.
19
19
* @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.
20
22
*/
21
23
constructor ( tokenRepository :ITokenRepository
22
24
, tokenGenerationService :ITokenGenerationService
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ export class UserService implements IUserService {
22
22
* @param username Represents the user name.
23
23
* @param password Represents the user password.
24
24
*/
25
- public async validateCredential ( username : string , password : string ) : Promise < boolean > {
25
+ public async validateCredentials ( username : string , password : string ) : Promise < boolean > {
26
26
27
27
let user :User = await this . _userRepository . getByName ( username ) ;
28
28
You can’t perform that action at this time.
0 commit comments