@@ -2,88 +2,22 @@ package goauth2
2
2
3
3
import (
4
4
"github.com/inklabs/rangedb"
5
- "github.com/inklabs/rangedb/pkg/clock"
6
5
)
7
6
8
- type authorizationCommandHandler struct {
9
- store rangedb.Store
10
- pendingEvents []rangedb.Event
11
- tokenGenerator TokenGenerator
12
- clock clock.Clock
7
+ type clientApplicationCommandAuthorization struct {
8
+ store rangedb.Store
9
+ pendingEvents []rangedb.Event
13
10
}
14
11
15
- func newAuthorizationCommandHandler (
16
- store rangedb.Store ,
17
- tokenGenerator TokenGenerator ,
18
- clock clock.Clock ,
19
- ) * authorizationCommandHandler {
20
- return & authorizationCommandHandler {
21
- store : store ,
22
- tokenGenerator : tokenGenerator ,
23
- clock : clock ,
12
+ func newClientApplicationCommandAuthorization (store rangedb.Store ) * clientApplicationCommandAuthorization {
13
+ return & clientApplicationCommandAuthorization {
14
+ store : store ,
24
15
}
25
16
}
26
17
27
- func (h * authorizationCommandHandler ) Handle (command Command ) bool {
18
+ func (h * clientApplicationCommandAuthorization ) Handle (command Command ) bool {
28
19
switch c := command .(type ) {
29
20
30
- case GrantUserAdministratorRole :
31
- grantingUser := h .loadResourceOwnerAggregate (c .GrantingUserID )
32
-
33
- if ! grantingUser .IsOnBoarded {
34
- h .emit (GrantUserAdministratorRoleWasRejectedDueToMissingGrantingUser {
35
- UserID : c .UserID ,
36
- GrantingUserID : c .GrantingUserID ,
37
- })
38
- return false
39
- }
40
-
41
- if ! grantingUser .IsAdministrator {
42
- h .emit (GrantUserAdministratorRoleWasRejectedDueToNonAdministrator {
43
- UserID : c .UserID ,
44
- GrantingUserID : c .GrantingUserID ,
45
- })
46
- return false
47
- }
48
-
49
- case AuthorizeUserToOnBoardClientApplications :
50
- authorizingUser := h .loadResourceOwnerAggregate (c .AuthorizingUserID )
51
-
52
- if ! authorizingUser .IsOnBoarded {
53
- h .emit (AuthorizeUserToOnBoardClientApplicationsWasRejectedDueToMissingAuthorizingUser {
54
- UserID : c .UserID ,
55
- AuthorizingUserID : c .AuthorizingUserID ,
56
- })
57
- return false
58
- }
59
-
60
- if ! authorizingUser .IsAdministrator {
61
- h .emit (AuthorizeUserToOnBoardClientApplicationsWasRejectedDueToNonAdministrator {
62
- UserID : c .UserID ,
63
- AuthorizingUserID : c .AuthorizingUserID ,
64
- })
65
- return false
66
- }
67
-
68
- case OnBoardClientApplication :
69
- resourceOwner := h .loadResourceOwnerAggregate (c .UserID )
70
-
71
- if ! resourceOwner .IsOnBoarded {
72
- h .emit (OnBoardClientApplicationWasRejectedDueToUnAuthorizeUser {
73
- ClientID : c .ClientID ,
74
- UserID : c .UserID ,
75
- })
76
- return false
77
- }
78
-
79
- if ! resourceOwner .IsAuthorizedToOnboardClientApplications {
80
- h .emit (OnBoardClientApplicationWasRejectedDueToUnAuthorizeUser {
81
- ClientID : c .ClientID ,
82
- UserID : c .UserID ,
83
- })
84
- return false
85
- }
86
-
87
21
case RequestAccessTokenViaImplicitGrant :
88
22
clientApplication := h .loadClientApplicationAggregate (c .ClientID )
89
23
@@ -195,18 +129,14 @@ func (h *authorizationCommandHandler) Handle(command Command) bool {
195
129
return true
196
130
}
197
131
198
- func (h * authorizationCommandHandler ) emit (events ... rangedb.Event ) {
132
+ func (h * clientApplicationCommandAuthorization ) emit (events ... rangedb.Event ) {
199
133
h .pendingEvents = append (h .pendingEvents , events ... )
200
134
}
201
135
202
- func (h * authorizationCommandHandler ) loadResourceOwnerAggregate (userID string ) * resourceOwner {
203
- return newResourceOwner (h .store .AllEventsByStream (resourceOwnerStream (userID )), h .tokenGenerator , h .clock )
204
- }
205
-
206
- func (h * authorizationCommandHandler ) loadClientApplicationAggregate (clientID string ) * clientApplication {
136
+ func (h * clientApplicationCommandAuthorization ) loadClientApplicationAggregate (clientID string ) * clientApplication {
207
137
return newClientApplication (h .store .AllEventsByStream (clientApplicationStream (clientID )))
208
138
}
209
139
210
- func (h * authorizationCommandHandler ) GetPendingEvents () []rangedb.Event {
140
+ func (h * clientApplicationCommandAuthorization ) GetPendingEvents () []rangedb.Event {
211
141
return h .pendingEvents
212
142
}
0 commit comments