Skip to content
Snippets Groups Projects
Commit 9cf3d5ae authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

add OIDC compaitibility for AT requests

parent b3c7a9eb
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,7 @@ func basicConfiguration() *pkg.MytokenConfiguration {
MytokenEndpointGrantTypesSupported: []pkgModel.GrantType{pkgModel.GrantTypeOIDCFlow, pkgModel.GrantTypeMytoken},
MytokenEndpointOIDCFlowsSupported: config.Get().Features.EnabledOIDCFlows,
ResponseTypesSupported: []pkgModel.ResponseType{pkgModel.ResponseTypeToken},
TokenEndpoint: utils.CombineURLPath(config.Get().IssuerURL, apiPaths.AccessTokenEndpoint),
}
}
......
......@@ -13,4 +13,5 @@ type MytokenConfiguration struct {
MytokenEndpointGrantTypesSupported []model.GrantType `json:"mytoken_endpoint_grant_types_supported"`
MytokenEndpointOIDCFlowsSupported []model.OIDCFlow `json:"mytoken_endpoint_oidc_flows_supported"`
ResponseTypesSupported []model.ResponseType `json:"response_types_supported"`
TokenEndpoint string `json:"token_endpoint"` // For compatibility with OIDC
}
package access
import (
"encoding/json"
"strings"
"github.com/gofiber/fiber/v2"
......@@ -32,10 +31,13 @@ import (
func HandleAccessTokenEndpoint(ctx *fiber.Ctx) error {
log.Debug("Handle access token request")
req := request.AccessTokenRequest{}
if err := json.Unmarshal(ctx.Body(), &req); err != nil {
if err := ctx.BodyParser(&req); err != nil {
return serverModel.ErrorToBadRequestErrorResponse(err).Send(ctx)
}
log.Trace("Parsed access token request")
if req.Mytoken == "" {
req.Mytoken = req.RefreshToken
}
if req.GrantType != model.GrantTypeMytoken {
res := serverModel.Response{
......
......@@ -9,6 +9,7 @@ import (
// AccessTokenRequest holds an request for an access token
type AccessTokenRequest struct {
api.AccessTokenRequest `json:",inline"`
GrantType model.GrantType `json:"grant_type"`
Mytoken token.Token `json:"mytoken"`
GrantType model.GrantType `json:"grant_type" xml:"grant_type" form:"grant_type"`
Mytoken token.Token `json:"mytoken" xml:"mytoken" form:"mytoken"`
RefreshToken token.Token `json:"refresh_token" xml:"refresh_token" form:"refresh_token"`
}
......@@ -2,10 +2,10 @@ package api
// AccessTokenRequest holds an request for an access token
type AccessTokenRequest struct {
Issuer string `json:"oidc_issuer,omitempty"`
GrantType string `json:"grant_type"`
Mytoken string `json:"mytoken"`
Scope string `json:"scope,omitempty"`
Audience string `json:"audience,omitempty"`
Comment string `json:"comment,omitempty"`
Issuer string `json:"oidc_issuer,omitempty" form:"issuer" xml:"oidc_issuer"`
GrantType string `json:"grant_type" form:"grant_type" xml:"grant_type"`
Mytoken string `json:"mytoken" form:"mytoken" xml:"mytoken"`
Scope string `json:"scope,omitempty" form:"scope" xml:"scope"`
Audience string `json:"audience,omitempty" form:"audience" xml:"audience"`
Comment string `json:"comment,omitempty" form:"comment" xml:"comment"`
}
......@@ -4,9 +4,8 @@ import (
"encoding/json"
"fmt"
"github.com/oidc-mytoken/server/pkg/api/v0"
yaml "gopkg.in/yaml.v3"
api "github.com/oidc-mytoken/server/pkg/api/v0"
)
// GrantType is an enum like type for grant types
......@@ -33,6 +32,9 @@ func NewGrantType(s string) GrantType {
return GrantType(i)
}
}
if s == "refresh_token" { // RT=MT compatibility
return GrantTypeMytoken
}
return -1
}
......@@ -74,6 +76,16 @@ func (g *GrantType) UnmarshalJSON(data []byte) error {
return nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface
func (g *GrantType) UnmarshalText(data []byte) error {
s := string(data)
*g = NewGrantType(s)
if !g.Valid() {
return fmt.Errorf("value '%s' not valid for GrantType", s)
}
return nil
}
// MarshalJSON implements the json.Marshaler interface
func (g GrantType) MarshalJSON() ([]byte, error) {
return json.Marshal(g.String())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment