Commit 6aab23c
Changed files (9)
pkg/dto/json_web_key_set.go
@@ -0,0 +1,5 @@
+package dto
+
+type JsonWebKeySet struct {
+ Keys []RsaJsonWebKey `json:"keys"`
+}
pkg/dto/open_id_configuration.go
@@ -0,0 +1,16 @@
+package dto
+
+type OpenIdConfiguration struct {
+ Issuer string `json:"issuer"`
+ AuthorizationEndpoint string `json:"authorization_endpoint"`
+ TokenEndpoint string `json:"token_endpoint"`
+ UserInfoEndpoint string `json:"userinfo_endpoint"`
+ JwksUri string `json:"jwks_uri"`
+ RevocationEndpoint string `json:"revocation_endpoint"`
+ ScopesSupported []string `json:"scopes_supported"`
+ ResponseTypesSupported []string `json:"response_types_supported"`
+ ResponseModesSupported []string `json:"response_modes_supported"`
+ SubjectTypesSupported []string `json:"subject_types_supported"`
+ IdTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
+ ClaimsSupported []string `json:"claims_supported"`
+}
pkg/dto/rsa_json_web_key.go
@@ -0,0 +1,9 @@
+package dto
+
+type RsaJsonWebKey struct {
+ E string `json:"e"`
+ KeyId string `json:"kid"`
+ KeyType string `json:"kty"`
+ N string `json:"n"`
+ Use string `json:"use"`
+}
pkg/web/json_web_key_sets.go
@@ -9,18 +9,6 @@ import (
"github.com/lestrrat-go/jwx/v2/jwk"
)
-type JsonWebKeySet struct {
- Keys []RsaJsonWebKey `json:"keys"`
-}
-
-type RsaJsonWebKey struct {
- E string `json:"e"`
- KeyId string `json:"kid"`
- KeyType string `json:"kty"`
- N string `json:"n"`
- Use string `json:"use"`
-}
-
func (h *HttpContext) JsonWebKeySets(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
privatePem, _ := pem.Decode(h.keyData)
pkg/web/json_web_key_sets_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "mokhan.ca/xlgmokha/oauth/pkg/dto"
)
func TestJsonWebKeySets(t *testing.T) {
@@ -31,7 +32,7 @@ func TestJsonWebKeySets(t *testing.T) {
assert.Equal(t, w.Header().Get("Content-Type"), "application/json")
- var c JsonWebKeySet
+ var c dto.JsonWebKeySet
json.NewDecoder(w.Body).Decode(&c)
assert.Equal(t, 1, len(c.Keys))
pkg/web/open_id_configuration.go
@@ -13,21 +13,6 @@ var (
tmpl = template.Must(template.New("").Parse(string(oidcConfig)))
)
-type OpenIdConfiguration struct {
- Issuer string `json:"issuer"`
- AuthorizationEndpoint string `json:"authorization_endpoint"`
- TokenEndpoint string `json:"token_endpoint"`
- UserInfoEndpoint string `json:"userinfo_endpoint"`
- JwksUri string `json:"jwks_uri"`
- RevocationEndpoint string `json:"revocation_endpoint"`
- ScopesSupported []string `json:"scopes_supported"`
- ResponseTypesSupported []string `json:"response_types_supported"`
- ResponseModesSupported []string `json:"response_modes_supported"`
- SubjectTypesSupported []string `json:"subject_types_supported"`
- IdTokenSigningAlgValuesSupported []string `json:"id_token_signing_alg_values_supported"`
- ClaimsSupported []string `json:"claims_supported"`
-}
-
func (h *HttpContext) OpenIdConfiguration(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
tmpl.Execute(w, struct{ Issuer string }{Issuer: h.issuer})
pkg/web/open_id_configuration_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "mokhan.ca/xlgmokha/oauth/pkg/dto"
)
func TestOpenIdConfiguration(t *testing.T) {
@@ -31,7 +32,7 @@ func TestOpenIdConfiguration(t *testing.T) {
assert.Equal(t, w.Header().Get("Content-Type"), "application/json")
- var c OpenIdConfiguration
+ var c dto.OpenIdConfiguration
json.NewDecoder(w.Body).Decode(&c)
assert.Equal(t, c.Issuer, "https://example.org")