Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package super
import (
"encoding/json"
"fmt"
"github.com/zachmann/mytoken/internal/config"
"github.com/zachmann/mytoken/internal/endpoints/token/super/pkg"
"github.com/zachmann/mytoken/internal/utils/ctxUtils"
"github.com/gofiber/fiber/v2"
"github.com/zachmann/mytoken/internal/model"
"github.com/zachmann/mytoken/internal/oidc/authcode"
)
func HandleSuperTokenEndpoint(ctx *fiber.Ctx) error {
grantType := ctxUtils.GetGrantType(ctx)
switch grantType {
case model.GrantTypeSuperToken:
return fmt.Errorf("not yet implemented")
case model.GrantTypeOIDCFlow:
return handleOIDCFlow(ctx)
case model.GrantTypeAccessToken:
return fmt.Errorf("not yet implemented")
case model.GrantTypePollingCode:
return fmt.Errorf("not yet implemented")
case model.GrantTypePrivateKeyJWT:
return fmt.Errorf("not yet implemented")
default:
ctx.SendStatus(fiber.StatusBadRequest)
return ctx.SendString("Bad grant_type")
}
}
func handleOIDCFlow(ctx *fiber.Ctx) error {
flow := ctxUtils.GetOIDCFlow(ctx)
switch flow {
case model.OIDCFlowAuthorizationCode:
req := pkg.NewAuthCodeFlowRequest()
if err := json.Unmarshal(ctx.Body(), &req); err != nil {
return err
}
provider, ok := config.Get().ProviderByIssuer[req.Issuer]
if !ok {
ctx.SendStatus(fiber.StatusBadRequest)
msg := fmt.Sprintf("Issuer '%s' not supported", req.Issuer)
return ctx.SendString(msg)
}
ret, err := authcode.InitAuthCodeFlow(provider, req)
if err != nil {
return err
}
return ctx.JSON(ret)
case model.OIDCFlowDevice:
return fmt.Errorf("not yet implemented")
default:
ctx.SendStatus(fiber.StatusBadRequest)
return ctx.SendString("Bad oidc_flow")
}
}