forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grant.go
50 lines (40 loc) · 1017 Bytes
/
grant.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
package handlers
import (
"errors"
"net/http"
"github.com/RangelReale/osin"
"github.com/openshift/origin/pkg/auth/api"
)
type GrantCheck struct {
check GrantChecker
handler GrantHandler
}
func NewGrantCheck(check GrantChecker, handler GrantHandler) *GrantCheck {
return &GrantCheck{check, handler}
}
func (h *GrantCheck) HandleAuthorize(ar *osin.AuthorizeRequest, w http.ResponseWriter, req *http.Request) (handled bool) {
if !ar.Authorized {
return
}
user, ok := ar.UserData.(api.UserInfo)
if !ok || user == nil {
h.handler.GrantError(errors.New("the provided user data is not api.UserInfo"), w, req)
return true
}
grant := &api.Grant{
Client: ar.Client,
Scope: ar.Scope,
Expiration: int64(ar.Expiration),
RedirectURI: ar.RedirectUri,
}
ok, err := h.check.HasAuthorizedClient(ar.Client, user, grant)
if err != nil {
h.handler.GrantError(err, w, req)
return true
}
if !ok {
h.handler.GrantNeeded(ar.Client, user, grant, w, req)
return true
}
return
}