File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
BotSharp.Abstraction/Users
BotSharp.Core/Users/Services Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ public interface IAuthenticationHook
7
7
{
8
8
Task < User > Authenticate ( string id , string password ) ;
9
9
void AddClaims ( List < Claim > claims ) ;
10
+ void BeforeSending ( Token token ) ;
10
11
}
Original file line number Diff line number Diff line change @@ -71,13 +71,13 @@ public async Task<Token> GetToken(string authorization)
71
71
record = db . GetUserByUserName ( id ) ;
72
72
}
73
73
74
+ var hooks = _services . GetServices < IAuthenticationHook > ( ) ;
74
75
if ( record == null || record . Source != "internal" )
75
76
{
76
77
// check 3rd party user
77
- var validators = _services . GetServices < IAuthenticationHook > ( ) ;
78
- foreach ( var validator in validators )
78
+ foreach ( var hook in hooks )
79
79
{
80
- var user = await validator . Authenticate ( id , password ) ;
80
+ var user = await hook . Authenticate ( id , password ) ;
81
81
if ( user == null )
82
82
{
83
83
continue ;
@@ -120,13 +120,20 @@ record = db.GetUserByUserName(id);
120
120
121
121
var accessToken = GenerateJwtToken ( record ) ;
122
122
var jwt = new JwtSecurityTokenHandler ( ) . ReadJwtToken ( accessToken ) ;
123
- return new Token
123
+ var token = new Token
124
124
{
125
125
AccessToken = accessToken ,
126
126
ExpireTime = jwt . Payload . Exp . Value ,
127
127
TokenType = "Bearer" ,
128
128
Scope = "api"
129
129
} ;
130
+
131
+ foreach ( var hook in hooks )
132
+ {
133
+ hook . BeforeSending ( token ) ;
134
+ }
135
+
136
+ return token ;
130
137
}
131
138
132
139
private string GenerateJwtToken ( User user )
You can’t perform that action at this time.
0 commit comments