Skip to content

Commit 99739a5

Browse files
authored
feat: adjust to new fosite changes (#34)
1 parent 5d70924 commit 99739a5

File tree

7 files changed

+102
-37
lines changed

7 files changed

+102
-37
lines changed

authorizationserver/oauth2.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package authorizationserver
33
import (
44
"crypto/rand"
55
"crypto/rsa"
6+
"github.com/ory/fosite"
67
"net/http"
78
"time"
89

@@ -30,8 +31,9 @@ func RegisterHandlers() {
3031
// 4. privateKey - required for id/jwt token generation.
3132
var (
3233
// Check the api documentation of `compose.Config` for further configuration options.
33-
config = &compose.Config{
34+
config = &fosite.Config{
3435
AccessTokenLifespan: time.Minute * 30,
36+
GlobalSecret: secret,
3537
// ...
3638
}
3739

@@ -74,7 +76,7 @@ var (
7476
)
7577

7678
// Build a fosite instance with all OAuth2 and OpenID Connect handlers enabled, plugging in our configurations as specified above.
77-
var oauth2 = compose.ComposeAllEnabled(config, store, secret, privateKey)
79+
var oauth2 = compose.ComposeAllEnabled(config, store, privateKey)
7880

7981
// A session is passed from the `/auth` to the `/token` endpoint. You probably want to store data like: "Who made the request",
8082
// "What organization does that person belong to" and so on.

authorizationserver/oauth2_auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func authEndpoint(rw http.ResponseWriter, req *http.Request) {
1515
ar, err := oauth2.NewAuthorizeRequest(ctx, req)
1616
if err != nil {
1717
log.Printf("Error occurred in NewAuthorizeRequest: %+v", err)
18-
oauth2.WriteAuthorizeError(rw, ar, err)
18+
oauth2.WriteAuthorizeError(ctx, rw, ar, err)
1919
return
2020
}
2121
// You have now access to authorizeRequest, Code ResponseTypes, Scopes ...
@@ -85,10 +85,10 @@ func authEndpoint(rw http.ResponseWriter, req *http.Request) {
8585
// * ...
8686
if err != nil {
8787
log.Printf("Error occurred in NewAuthorizeResponse: %+v", err)
88-
oauth2.WriteAuthorizeError(rw, ar, err)
88+
oauth2.WriteAuthorizeError(ctx, rw, ar, err)
8989
return
9090
}
9191

9292
// Last but not least, send the response!
93-
oauth2.WriteAuthorizeResponse(rw, ar, response)
93+
oauth2.WriteAuthorizeResponse(ctx, rw, ar, response)
9494
}

authorizationserver/oauth2_introspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ func introspectionEndpoint(rw http.ResponseWriter, req *http.Request) {
1111
ir, err := oauth2.NewIntrospectionRequest(ctx, req, mySessionData)
1212
if err != nil {
1313
log.Printf("Error occurred in NewIntrospectionRequest: %+v", err)
14-
oauth2.WriteIntrospectionError(rw, err)
14+
oauth2.WriteIntrospectionError(ctx, rw, err)
1515
return
1616
}
1717

18-
oauth2.WriteIntrospectionResponse(rw, ir)
18+
oauth2.WriteIntrospectionResponse(ctx, rw, ir)
1919
}

authorizationserver/oauth2_revoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func revokeEndpoint(rw http.ResponseWriter, req *http.Request) {
1212
err := oauth2.NewRevocationRequest(ctx, req)
1313

1414
// All done, send the response.
15-
oauth2.WriteRevocationResponse(rw, err)
15+
oauth2.WriteRevocationResponse(ctx, rw, err)
1616
}

authorizationserver/oauth2_token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func tokenEndpoint(rw http.ResponseWriter, req *http.Request) {
2121
// * ...
2222
if err != nil {
2323
log.Printf("Error occurred in NewAccessRequest: %+v", err)
24-
oauth2.WriteAccessError(rw, accessRequest, err)
24+
oauth2.WriteAccessError(ctx, rw, accessRequest, err)
2525
return
2626
}
2727

@@ -39,12 +39,12 @@ func tokenEndpoint(rw http.ResponseWriter, req *http.Request) {
3939
response, err := oauth2.NewAccessResponse(ctx, accessRequest)
4040
if err != nil {
4141
log.Printf("Error occurred in NewAccessResponse: %+v", err)
42-
oauth2.WriteAccessError(rw, accessRequest, err)
42+
oauth2.WriteAccessError(ctx, rw, accessRequest, err)
4343
return
4444
}
4545

4646
// All done, send the response.
47-
oauth2.WriteAccessResponse(rw, accessRequest, response)
47+
oauth2.WriteAccessResponse(ctx, rw, accessRequest, response)
4848

4949
// The client now has a valid access token
5050
}

go.mod

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
module github.com/ory/fosite-example
22

3-
go 1.13
3+
go 1.17
44

55
require (
6-
github.com/ory/fosite v0.40.3-0.20210618140333-a4ce3544c299
7-
golang.org/x/net v0.0.0-20201021035429-f5854403a974
6+
github.com/ory/fosite v0.42.3-0.20220508104133-3a0c9520791b
7+
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f
88
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
99
)
10+
11+
require (
12+
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
13+
github.com/cespare/xxhash v1.1.0 // indirect
14+
github.com/dgraph-io/ristretto v0.0.3 // indirect
15+
github.com/fsnotify/fsnotify v1.4.9 // indirect
16+
github.com/golang/protobuf v1.4.2 // indirect
17+
github.com/google/uuid v1.1.2 // indirect
18+
github.com/gorilla/websocket v1.4.2 // indirect
19+
github.com/hashicorp/hcl v1.0.0 // indirect
20+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
21+
github.com/magiconair/properties v1.8.1 // indirect
22+
github.com/mattn/goveralls v0.0.6 // indirect
23+
github.com/mitchellh/mapstructure v1.3.2 // indirect
24+
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
25+
github.com/ory/go-acc v0.2.6 // indirect
26+
github.com/ory/go-convenience v0.1.0 // indirect
27+
github.com/ory/viper v1.7.5 // indirect
28+
github.com/ory/x v0.0.214 // indirect
29+
github.com/pborman/uuid v1.2.0 // indirect
30+
github.com/pelletier/go-toml v1.8.0 // indirect
31+
github.com/pkg/errors v0.9.1 // indirect
32+
github.com/spf13/afero v1.3.2 // indirect
33+
github.com/spf13/cast v1.3.2-0.20200723214538-8d17101741c8 // indirect
34+
github.com/spf13/cobra v1.0.0 // indirect
35+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
36+
github.com/spf13/pflag v1.0.5 // indirect
37+
github.com/subosito/gotenv v1.2.0 // indirect
38+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
39+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
40+
golang.org/x/text v0.3.7 // indirect
41+
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023 // indirect
42+
google.golang.org/appengine v1.6.5 // indirect
43+
google.golang.org/protobuf v1.25.0 // indirect
44+
gopkg.in/ini.v1 v1.57.0 // indirect
45+
gopkg.in/square/go-jose.v2 v2.5.2-0.20210529014059-a5c7eec3c614 // indirect
46+
gopkg.in/yaml.v2 v2.3.0 // indirect
47+
)

0 commit comments

Comments
 (0)