Skip to content

Commit 3033b49

Browse files
committed
We can provide the full request.
1 parent b46cf9f commit 3033b49

File tree

2 files changed

+593
-592
lines changed

2 files changed

+593
-592
lines changed

server/handler.go

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
package server
2-
3-
import (
4-
"net/http"
5-
"time"
6-
7-
"github.com/go-oauth2/oauth2/v4"
8-
"github.com/go-oauth2/oauth2/v4/errors"
9-
)
10-
11-
type (
12-
// ClientInfoHandler get client info from request
13-
ClientInfoHandler func(r *http.Request) (clientID, clientSecret string, err error)
14-
15-
// ClientAuthorizedHandler check the client allows to use this authorization grant type
16-
ClientAuthorizedHandler func(clientID string, grant oauth2.GrantType) (allowed bool, err error)
17-
18-
// ClientScopeHandler check the client allows to use scope
19-
ClientScopeHandler func(clientID, scope string) (allowed bool, err error)
20-
21-
// UserAuthorizationHandler get user id from request authorization
22-
UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)
23-
24-
// PasswordAuthorizationHandler get user id from username and password
25-
PasswordAuthorizationHandler func(username, password string) (userID string, err error)
26-
27-
// RefreshingScopeHandler check the scope of the refreshing token
28-
RefreshingScopeHandler func(newScope, oldScope string) (allowed bool, err error)
29-
30-
// ResponseErrorHandler response error handing
31-
ResponseErrorHandler func(re *errors.Response)
32-
33-
// InternalErrorHandler internal error handing
34-
InternalErrorHandler func(err error) (re *errors.Response)
35-
36-
// AuthorizeScopeHandler set the authorized scope
37-
AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)
38-
39-
// AccessTokenExpHandler set expiration date for the access token
40-
AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)
41-
42-
// ExtensionFieldsHandler in response to the access token with the extension of the field
43-
ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})
44-
)
45-
46-
// ClientFormHandler get client data from form
47-
func ClientFormHandler(r *http.Request) (string, string, error) {
48-
clientID := r.Form.Get("client_id")
49-
if clientID == "" {
50-
return "", "", errors.ErrInvalidClient
51-
}
52-
clientSecret := r.Form.Get("client_secret")
53-
return clientID, clientSecret, nil
54-
}
55-
56-
// ClientBasicHandler get client data from basic authorization
57-
func ClientBasicHandler(r *http.Request) (string, string, error) {
58-
username, password, ok := r.BasicAuth()
59-
if !ok {
60-
return "", "", errors.ErrInvalidClient
61-
}
62-
return username, password, nil
63-
}
1+
package server
2+
3+
import (
4+
"net/http"
5+
"time"
6+
7+
"github.com/go-oauth2/oauth2/v4"
8+
"github.com/go-oauth2/oauth2/v4/errors"
9+
)
10+
11+
type (
12+
// ClientInfoHandler get client info from request
13+
ClientInfoHandler func(r *http.Request) (clientID, clientSecret string, err error)
14+
15+
// ClientAuthorizedHandler check the client allows to use this authorization grant type
16+
ClientAuthorizedHandler func(clientID string, grant oauth2.GrantType) (allowed bool, err error)
17+
18+
// ClientScopeHandler check the client allows to use scope
19+
ClientScopeHandler func(tgr *oauth2.TokenGenerateRequest) (allowed bool, err error)
20+
21+
// UserAuthorizationHandler get user id from request authorization
22+
UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)
23+
24+
// PasswordAuthorizationHandler get user id from username and password
25+
PasswordAuthorizationHandler func(username, password string) (userID string, err error)
26+
27+
// RefreshingScopeHandler check the scope of the refreshing token
28+
RefreshingScopeHandler func(tgr *oauth2.TokenGenerateRequest, oldScope string) (allowed bool, err error)
29+
30+
// ResponseErrorHandler response error handing
31+
ResponseErrorHandler func(re *errors.Response)
32+
33+
// InternalErrorHandler internal error handing
34+
InternalErrorHandler func(err error) (re *errors.Response)
35+
36+
// AuthorizeScopeHandler set the authorized scope
37+
AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)
38+
39+
// AccessTokenExpHandler set expiration date for the access token
40+
AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)
41+
42+
// ExtensionFieldsHandler in response to the access token with the extension of the field
43+
ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})
44+
)
45+
46+
// ClientFormHandler get client data from form
47+
func ClientFormHandler(r *http.Request) (string, string, error) {
48+
clientID := r.Form.Get("client_id")
49+
if clientID == "" {
50+
return "", "", errors.ErrInvalidClient
51+
}
52+
clientSecret := r.Form.Get("client_secret")
53+
return clientID, clientSecret, nil
54+
}
55+
56+
// ClientBasicHandler get client data from basic authorization
57+
func ClientBasicHandler(r *http.Request) (string, string, error) {
58+
username, password, ok := r.BasicAuth()
59+
if !ok {
60+
return "", "", errors.ErrInvalidClient
61+
}
62+
return username, password, nil
63+
}

0 commit comments

Comments
 (0)