-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorization_server.go
59 lines (51 loc) · 1.87 KB
/
authorization_server.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
package go_ciba
import (
"log"
"github.com/adisazhar123/go-ciba/grant"
"github.com/adisazhar123/go-ciba/repository"
"github.com/adisazhar123/go-ciba/service"
"github.com/adisazhar123/go-ciba/util"
)
type AuthorizationServerInterface interface {
AddGrant(grant grant.GrantTypeInterface)
AddService(grantService service.GrantServiceInterface)
HandleCibaRequest(request *service.AuthenticationRequest) (*service.AuthenticationResponse, *util.OidcError)
HandleConsentRequest(request *service.ConsentRequest) *util.OidcError
}
type authorizationServer struct {
grantServices map[string]service.GrantServiceInterface
dataStore repository.DataStoreInterface
}
func NewAuthorizationServer(ds repository.DataStoreInterface) *authorizationServer {
return &authorizationServer{
grantServices: make(map[string]service.GrantServiceInterface),
dataStore: ds,
}
}
func (as *authorizationServer) AddService(gs service.GrantServiceInterface) {
_, exist := as.grantServices[gs.GetGrantIdentifier()]
if !exist {
as.grantServices[gs.GetGrantIdentifier()] = gs
log.Printf("added grant type: %s\n", gs.GetGrantIdentifier())
}
}
func (as *authorizationServer) HandleCibaRequest(request *service.AuthenticationRequest) (*service.AuthenticationResponse, *util.OidcError) {
if _, exist := as.grantServices[grant.IdentifierCiba]; !exist {
return nil, util.ErrGeneral
}
cs, ok := as.grantServices[grant.IdentifierCiba].(service.CibaServiceInterface)
if !ok {
return nil, util.ErrGeneral
}
return cs.HandleAuthenticationRequest(request)
}
func (as *authorizationServer) HandleConsentRequest(request *service.ConsentRequest) *util.OidcError {
if _, exist := as.grantServices[grant.IdentifierCiba]; !exist {
return util.ErrGeneral
}
cs, ok := as.grantServices[grant.IdentifierCiba].(service.CibaServiceInterface)
if !ok {
return util.ErrGeneral
}
return cs.HandleConsentRequest(request)
}