generated from fluffy-bunny/fluffycore-grpc-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oidc-login-passkey.go
115 lines (96 loc) · 3.78 KB
/
oidc-login-passkey.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package oidcloginpasskey
import (
"net/http"
di "github.com/fluffy-bunny/fluffy-dozm-di"
contracts_config "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/config"
contracts_cookies "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/cookies"
contracts_oidc_session "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/contracts/oidc_session"
services_echo_handlers_base "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/services/echo/handlers/base"
wellknown_echo "github.com/fluffy-bunny/fluffycore-rage-identity/pkg/wellknown/echo"
contracts_handler "github.com/fluffy-bunny/fluffycore/echo/contracts/handler"
echo "github.com/labstack/echo/v4"
zerolog "github.com/rs/zerolog"
)
type (
service struct {
*services_echo_handlers_base.BaseHandler
config *contracts_config.Config
wellknownCookies contracts_cookies.IWellknownCookies
oidcSession contracts_oidc_session.IOIDCSession
signinResponse *contracts_cookies.GetSigninUserNameCookieResponse
}
)
var stemService = (*service)(nil)
func init() {
var _ contracts_handler.IHandler = stemService
}
const (
// make sure only one is shown. This is an internal error code to point the developer to the code that is failing
InternalError_OIDCLoginPasskey_001 = "rg-oidclogin-passkey-001"
InternalError_OIDCLoginPasskey_002 = "rg-oidclogin-passkey-002"
InternalError_OIDCLoginPasskey_003 = "rg-oidclogin-passkey-003"
InternalError_OIDCLoginPasskey_004 = "rg-oidclogin-passkey-004"
InternalError_OIDCLoginPasskey_005 = "rg-oidclogin-passkey-005"
InternalError_OIDCLoginPasskey_006 = "rg-oidclogin-passkey-006"
InternalError_OIDCLoginPasskey_007 = "rg-oidclogin-passkey-007"
InternalError_OIDCLoginPasskey_008 = "rg-oidclogin-passkey-008"
InternalError_OIDCLoginPasskey_009 = "rg-oidclogin-passkey-009"
InternalError_OIDCLoginPasskey_010 = "rg-oidclogin-passkey-010"
InternalError_OIDCLoginPasskey_011 = "rg-oidclogin-passkey-011"
InternalError_OIDCLoginPasskey_099 = "rg-oidclogin-passkey-099"
)
func (s *service) Ctor(
config *contracts_config.Config,
container di.Container,
wellknownCookies contracts_cookies.IWellknownCookies,
oidcSession contracts_oidc_session.IOIDCSession,
) (*service, error) {
return &service{
BaseHandler: services_echo_handlers_base.NewBaseHandler(container),
config: config,
wellknownCookies: wellknownCookies,
oidcSession: oidcSession,
}, nil
}
// AddScopedIHandler registers the *service as a singleton.
func AddScopedIHandler(builder di.ContainerBuilder) {
contracts_handler.AddScopedIHandleWithMetadata[*service](builder,
stemService.Ctor,
[]contracts_handler.HTTPVERB{
contracts_handler.POST,
contracts_handler.GET,
},
wellknown_echo.OIDCLoginPasskeyPath,
)
}
func (s *service) GetMiddleware() []echo.MiddlewareFunc {
return []echo.MiddlewareFunc{}
}
func (s *service) DoPost(c echo.Context) error {
r := c.Request()
// is the request get or post?
ctx := r.Context()
log := zerolog.Ctx(ctx).With().Logger()
log.Debug().Msg("OIDCLoginPasskey")
return s.Render(c, http.StatusOK, "oidc/oidcloginpasskey/index", map[string]interface{}{})
}
func (s *service) Do(c echo.Context) error {
r := c.Request()
ctx := r.Context()
log := zerolog.Ctx(ctx).With().Logger()
signinResponse, err := s.wellknownCookies.GetSigninUserNameCookie(c)
if err != nil {
log.Error().Err(err).Msg("GetSigninUserNameCookie")
return s.TeleportBackToLogin(c, InternalError_OIDCLoginPasskey_004)
}
s.signinResponse = signinResponse
// is the request get or post?
switch r.Method {
case http.MethodGet:
return s.DoPost(c)
case http.MethodPost:
return s.DoPost(c)
}
// return not found
return c.NoContent(http.StatusNotFound)
}