-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrefresh_token_process_manager.go
60 lines (51 loc) · 1.71 KB
/
refresh_token_process_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package goauth2
import (
"github.com/inklabs/rangedb"
)
type refreshTokenProcessManager struct {
dispatch CommandDispatcher
authorizationCodeRefreshtokens *AuthorizationCodeRefreshTokens
}
func newRefreshTokenProcessManager(
commandDispatcher CommandDispatcher,
authorizationCodeRefreshTokens *AuthorizationCodeRefreshTokens,
) *refreshTokenProcessManager {
return &refreshTokenProcessManager{
dispatch: commandDispatcher,
authorizationCodeRefreshtokens: authorizationCodeRefreshTokens,
}
}
// Accept receives a rangedb.Record.
func (r *refreshTokenProcessManager) Accept(record *rangedb.Record) {
switch event := record.Data.(type) {
case *RefreshTokenWasIssuedToUserViaROPCGrant:
r.dispatch(IssueRefreshTokenToUser{
RefreshToken: event.RefreshToken,
UserID: event.UserID,
ClientID: event.ClientID,
Scope: event.Scope,
})
case *RefreshTokenWasIssuedToUserViaAuthorizationCodeGrant:
r.dispatch(IssueRefreshTokenToUser{
RefreshToken: event.RefreshToken,
UserID: event.UserID,
ClientID: event.ClientID,
Scope: event.Scope,
})
case *RefreshTokenWasIssuedToUserViaRefreshTokenGrant:
r.dispatch(IssueRefreshTokenToUser{
RefreshToken: event.NextRefreshToken,
UserID: event.UserID,
ClientID: event.ClientID,
Scope: event.Scope,
})
case *RequestAccessTokenViaAuthorizationCodeGrantWasRejectedDueToPreviouslyUsedAuthorizationCode:
for _, refreshToken := range r.authorizationCodeRefreshtokens.GetTokens(event.AuthorizationCode) {
r.dispatch(RevokeRefreshTokenFromUser{
RefreshToken: refreshToken,
UserID: event.UserID,
ClientID: event.ClientID,
})
}
}
}