Skip to content

Commit 68172d1

Browse files
authored
Merge pull request #178 from futuresBetter/pr/158
Pr/158
2 parents e71e51f + b0f3e66 commit 68172d1

File tree

4 files changed

+669
-656
lines changed

4 files changed

+669
-656
lines changed

.editorconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.go]
2+
end_of_line = crlf

manage/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (m *Manager) GenerateAuthToken(ctx context.Context, rt oauth2.ResponseType,
218218
}
219219
return ti, nil
220220
}
221-
221+
222222
// get authorization code data
223223
func (m *Manager) getAuthorizationCode(ctx context.Context, code string) (oauth2.TokenInfo, error) {
224224
ti, err := m.tokenStore.GetByCode(ctx, code)

server/handler.go

+66-66
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
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-
// RefreshingValidationHandler check if refresh_token is still valid. eg no revocation or other
31-
RefreshingValidationHandler func(ti oauth2.TokenInfo) (allowed bool, err error)
32-
33-
// ResponseErrorHandler response error handing
34-
ResponseErrorHandler func(re *errors.Response)
35-
36-
// InternalErrorHandler internal error handing
37-
InternalErrorHandler func(err error) (re *errors.Response)
38-
39-
// AuthorizeScopeHandler set the authorized scope
40-
AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)
41-
42-
// AccessTokenExpHandler set expiration date for the access token
43-
AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)
44-
45-
// ExtensionFieldsHandler in response to the access token with the extension of the field
46-
ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})
47-
)
48-
49-
// ClientFormHandler get client data from form
50-
func ClientFormHandler(r *http.Request) (string, string, error) {
51-
clientID := r.Form.Get("client_id")
52-
if clientID == "" {
53-
return "", "", errors.ErrInvalidClient
54-
}
55-
clientSecret := r.Form.Get("client_secret")
56-
return clientID, clientSecret, nil
57-
}
58-
59-
// ClientBasicHandler get client data from basic authorization
60-
func ClientBasicHandler(r *http.Request) (string, string, error) {
61-
username, password, ok := r.BasicAuth()
62-
if !ok {
63-
return "", "", errors.ErrInvalidClient
64-
}
65-
return username, password, nil
66-
}
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+
// RefreshingValidationHandler check if refresh_token is still valid. eg no revocation or other
31+
RefreshingValidationHandler func(ti oauth2.TokenInfo) (allowed bool, err error)
32+
33+
// ResponseErrorHandler response error handing
34+
ResponseErrorHandler func(re *errors.Response)
35+
36+
// InternalErrorHandler internal error handing
37+
InternalErrorHandler func(err error) (re *errors.Response)
38+
39+
// AuthorizeScopeHandler set the authorized scope
40+
AuthorizeScopeHandler func(w http.ResponseWriter, r *http.Request) (scope string, err error)
41+
42+
// AccessTokenExpHandler set expiration date for the access token
43+
AccessTokenExpHandler func(w http.ResponseWriter, r *http.Request) (exp time.Duration, err error)
44+
45+
// ExtensionFieldsHandler in response to the access token with the extension of the field
46+
ExtensionFieldsHandler func(ti oauth2.TokenInfo) (fieldsValue map[string]interface{})
47+
)
48+
49+
// ClientFormHandler get client data from form
50+
func ClientFormHandler(r *http.Request) (string, string, error) {
51+
clientID := r.Form.Get("client_id")
52+
if clientID == "" {
53+
return "", "", errors.ErrInvalidClient
54+
}
55+
clientSecret := r.Form.Get("client_secret")
56+
return clientID, clientSecret, nil
57+
}
58+
59+
// ClientBasicHandler get client data from basic authorization
60+
func ClientBasicHandler(r *http.Request) (string, string, error) {
61+
username, password, ok := r.BasicAuth()
62+
if !ok {
63+
return "", "", errors.ErrInvalidClient
64+
}
65+
return username, password, nil
66+
}

0 commit comments

Comments
 (0)