summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2022-04-29 14:02:48 -0600
committermo khan <mo@mokhan.ca>2022-04-29 14:02:48 -0600
commit6aab23ccf3e701cb85f3d8ff4400e4a2bab4cfaf (patch)
treea0f3f4df30c901d8fb60c0c821b14b944a0fb9cb
parente77954de0fbaf23fbddf2bdf6516a630a022c85d (diff)
refactor: move structs to dto package
-rw-r--r--pkg/dto/authorization_request.go10
-rw-r--r--pkg/dto/json_web_key_set.go5
-rw-r--r--pkg/dto/open_id_configuration.go16
-rw-r--r--pkg/dto/rsa_json_web_key.go9
-rw-r--r--pkg/web/authorize.go14
-rw-r--r--pkg/web/json_web_key_sets.go12
-rw-r--r--pkg/web/json_web_key_sets_test.go3
-rw-r--r--pkg/web/open_id_configuration.go15
-rw-r--r--pkg/web/open_id_configuration_test.go3
9 files changed, 47 insertions, 40 deletions
diff --git a/pkg/dto/authorization_request.go b/pkg/dto/authorization_request.go
new file mode 100644
index 0000000..17aa4e5
--- /dev/null
+++ b/pkg/dto/authorization_request.go
@@ -0,0 +1,10 @@
+package dto
+
+type AuthorizationRequest struct {
+ ResponseType string
+ Scope string
+ ClientId string
+ State string
+ RedirectUri string
+ Nonce string
+}
diff --git a/pkg/dto/json_web_key_set.go b/pkg/dto/json_web_key_set.go
new file mode 100644
index 0000000..80789ee
--- /dev/null
+++ b/pkg/dto/json_web_key_set.go
@@ -0,0 +1,5 @@
+package dto
+
+type JsonWebKeySet struct {
+ Keys []RsaJsonWebKey `json:"keys"`
+}
diff --git a/pkg/dto/open_id_configuration.go b/pkg/dto/open_id_configuration.go
new file mode 100644
index 0000000..4f2ad03
--- /dev/null
+++ b/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"`
+}
diff --git a/pkg/dto/rsa_json_web_key.go b/pkg/dto/rsa_json_web_key.go
new file mode 100644
index 0000000..7a17651
--- /dev/null
+++ b/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"`
+}
diff --git a/pkg/web/authorize.go b/pkg/web/authorize.go
index b223699..87de962 100644
--- a/pkg/web/authorize.go
+++ b/pkg/web/authorize.go
@@ -5,23 +5,15 @@ import (
"net/http"
"github.com/hashicorp/uuid"
+ "mokhan.ca/xlgmokha/oauth/pkg/dto"
)
-type AuthorizationRequest struct {
- ResponseType string
- Scope string
- ClientId string
- State string
- RedirectUri string
- Nonce string
-}
-
func (h *HttpContext) Authorize(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
responseType := r.FormValue("response_type")
if responseType == "code" {
// Authorization Code Flow https://openid.net/specs/openid-connect-core-1_0.html#CodeFlowAuth
- ar := &AuthorizationRequest{
+ ar := &dto.AuthorizationRequest{
ResponseType: r.FormValue("response_type"),
Scope: r.FormValue("scope"),
ClientId: r.FormValue("client_id"),
@@ -34,7 +26,7 @@ func (h *HttpContext) Authorize(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, url, 302)
} else if responseType == "id_token token" || responseType == "id_token" {
// Implicit Flow https://openid.net/specs/openid-connect-core-1_0.html#ImplicitFlowAuth
- ar := &AuthorizationRequest{
+ ar := &dto.AuthorizationRequest{
ResponseType: r.FormValue("response_type"),
RedirectUri: r.FormValue("redirect_uri"),
Nonce: r.FormValue("nonce"),
diff --git a/pkg/web/json_web_key_sets.go b/pkg/web/json_web_key_sets.go
index 485c0eb..2d32845 100644
--- a/pkg/web/json_web_key_sets.go
+++ b/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)
diff --git a/pkg/web/json_web_key_sets_test.go b/pkg/web/json_web_key_sets_test.go
index 578860f..1ecb7ff 100644
--- a/pkg/web/json_web_key_sets_test.go
+++ b/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))
diff --git a/pkg/web/open_id_configuration.go b/pkg/web/open_id_configuration.go
index 29febc0..7e2149a 100644
--- a/pkg/web/open_id_configuration.go
+++ b/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})
diff --git a/pkg/web/open_id_configuration_test.go b/pkg/web/open_id_configuration_test.go
index d7b04d2..1249a14 100644
--- a/pkg/web/open_id_configuration_test.go
+++ b/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")