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
77{
88 Task < User > Authenticate ( string id , string password ) ;
99 void AddClaims ( List < Claim > claims ) ;
10+ void BeforeSending ( Token token ) ;
1011}
Original file line number Diff line number Diff line change @@ -71,13 +71,13 @@ public async Task<Token> GetToken(string authorization)
7171 record = db . GetUserByUserName ( id ) ;
7272 }
7373
74+ var hooks = _services . GetServices < IAuthenticationHook > ( ) ;
7475 if ( record == null || record . Source != "internal" )
7576 {
7677 // check 3rd party user
77- var validators = _services . GetServices < IAuthenticationHook > ( ) ;
78- foreach ( var validator in validators )
78+ foreach ( var hook in hooks )
7979 {
80- var user = await validator . Authenticate ( id , password ) ;
80+ var user = await hook . Authenticate ( id , password ) ;
8181 if ( user == null )
8282 {
8383 continue ;
@@ -120,13 +120,20 @@ record = db.GetUserByUserName(id);
120120
121121 var accessToken = GenerateJwtToken ( record ) ;
122122 var jwt = new JwtSecurityTokenHandler ( ) . ReadJwtToken ( accessToken ) ;
123- return new Token
123+ var token = new Token
124124 {
125125 AccessToken = accessToken ,
126126 ExpireTime = jwt . Payload . Exp . Value ,
127127 TokenType = "Bearer" ,
128128 Scope = "api"
129129 } ;
130+
131+ foreach ( var hook in hooks )
132+ {
133+ hook . BeforeSending ( token ) ;
134+ }
135+
136+ return token ;
130137 }
131138
132139 private string GenerateJwtToken ( User user )
You can’t perform that action at this time.
0 commit comments