Skip to content

Commit 3ef29f4

Browse files
committed
Updated
1 parent 2f083c3 commit 3ef29f4

File tree

3 files changed

+3
-594
lines changed

3 files changed

+3
-594
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[*.go]
2-
end_of_line = lf
2+
end_of_line = cr

server/handler.go

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1 @@
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-
}
1+
package serverimport ( "net/http" "time" "github.com/go-oauth2/oauth2/v4" "github.com/go-oauth2/oauth2/v4/errors")type ( // ClientInfoHandler get client info from request ClientInfoHandler func(r *http.Request) (clientID, clientSecret string, err error) // ClientAuthorizedHandler check the client allows to use this authorization grant type ClientAuthorizedHandler func(clientID string, grant oauth2.GrantType) (allowed bool, err error) // ClientScopeHandler check the client allows to use scope ClientScopeHandler func(tgr *oauth2.TokenGenerateRequest) (allowed bool, err error) // UserAuthorizationHandler get user id from request authorization UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error) // PasswordAuthorizationHandler get user id from username and password PasswordAuthorizationHandler func(username, password string) (userID string, err error) // RefreshingScopeHandler check the scope of the refreshing token RefreshingScopeHandler func(tgr *oauth2.TokenGenerateRequest, oldScope string) (allowed bool, err error) // ResponseErrorHandler response error handing ResponseErrorHandler func(re *errors.Response) // InternalErrorHandler internal error handing InternalErrorHandler func(err error) (re *errors.Response) // AuthorizeScopeHandler set the authorized scope AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error) // AccessTokenExpHandler set expiration date for the access token AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error) // ExtensionFieldsHandler in response to the access token with the extension of the field ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{}))// ClientFormHandler get client data from formfunc ClientFormHandler(r *http.Request) (string, string, error) { clientID := r.Form.Get("client_id") if clientID == "" { return "", "", errors.ErrInvalidClient } clientSecret := r.Form.Get("client_secret") return clientID, clientSecret, nil}// ClientBasicHandler get client data from basic authorizationfunc ClientBasicHandler(r *http.Request) (string, string, error) { username, password, ok := r.BasicAuth() if !ok { return "", "", errors.ErrInvalidClient } return username, password, nil}

0 commit comments

Comments
 (0)