Skip to content

Commit 361d227

Browse files
authored
Merge pull request #220 from aurelien-semence/per-client-authorization
Per client authorization
2 parents 446d602 + fa861a7 commit 361d227

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

example/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func main() {
6464

6565
srv := server.NewServer(server.NewConfig(), manager)
6666

67-
srv.SetPasswordAuthorizationHandler(func(ctx context.Context, username, password string) (userID string, err error) {
67+
srv.SetPasswordAuthorizationHandler(func(ctx context.Context, clientID, username, password string) (userID string, err error) {
6868
if username == "test" && password == "test" {
6969
userID = "test"
7070
}

server/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type (
2323
UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)
2424

2525
// PasswordAuthorizationHandler get user id from username and password
26-
PasswordAuthorizationHandler func(ctx context.Context, username, password string) (userID string, err error)
26+
PasswordAuthorizationHandler func(ctx context.Context, clientID, username, password string) (userID string, err error)
2727

2828
// RefreshingScopeHandler check the scope of the refreshing token
2929
RefreshingScopeHandler func(tgr *oauth2.TokenGenerateRequest, oldScope string) (allowed bool, err error)

server/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewServer(cfg *Config, manager oauth2.Manager) *Server {
3232
return "", errors.ErrAccessDenied
3333
}
3434

35-
srv.PasswordAuthorizationHandler = func(ctx context.Context, username, password string) (string, error) {
35+
srv.PasswordAuthorizationHandler = func(ctx context.Context, clientID, username, password string) (string, error) {
3636
return "", errors.ErrAccessDenied
3737
}
3838
return srv
@@ -357,7 +357,7 @@ func (s *Server) ValidationTokenRequest(r *http.Request) (oauth2.GrantType, *oau
357357
return "", nil, errors.ErrInvalidRequest
358358
}
359359

360-
userID, err := s.PasswordAuthorizationHandler(r.Context(), username, password)
360+
userID, err := s.PasswordAuthorizationHandler(r.Context(), clientID, username, password)
361361
if err != nil {
362362
return "", nil, err
363363
} else if userID == "" {

server/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func TestPasswordCredentials(t *testing.T) {
251251

252252
manager.MapClientStorage(clientStore(""))
253253
srv = server.NewDefaultServer(manager)
254-
srv.SetPasswordAuthorizationHandler(func(ctx context.Context, username, password string) (userID string, err error) {
254+
srv.SetPasswordAuthorizationHandler(func(ctx context.Context, clientID, username, password string) (userID string, err error) {
255255
if username == "admin" && password == "123456" {
256256
userID = "000000"
257257
return

0 commit comments

Comments
 (0)