replaced fmt.Println with logger usage
This commit is contained in:
@@ -177,10 +177,6 @@ func (p *Platform) HandleNewAuthCode(ctx context.Context, acctID int64, state, a
|
|||||||
return false, fmt.Errorf("failed to parse response body: %w", err)
|
return false, fmt.Errorf("failed to parse response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("new access token:", accessToken)
|
|
||||||
fmt.Println("new refresh token:", refreshToken)
|
|
||||||
fmt.Println("new token expiration:", expiration)
|
|
||||||
|
|
||||||
// look up user's shop id
|
// look up user's shop id
|
||||||
|
|
||||||
shopID, err := p.getNewUserShopID(ctx, accessToken, userID)
|
shopID, err := p.getNewUserShopID(ctx, accessToken, userID)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func (s *Server) logoutPage(r *http.Request) (response.Response, error) {
|
|||||||
|
|
||||||
if ck, err := r.Cookie("access_token"); err == nil && ck != nil {
|
if ck, err := r.Cookie("access_token"); err == nil && ck != nil {
|
||||||
if err := s.auth.DeleteOAuthTokens(r.Context(), ck.Value); err != nil {
|
if err := s.auth.DeleteOAuthTokens(r.Context(), ck.Value); err != nil {
|
||||||
fmt.Println("[ERROR] failed to delete auth token:", err)
|
s.log.Error("failed to delete auth token", "error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Auth struct {
|
Auth struct {
|
||||||
|
log *slog.Logger
|
||||||
auth *authentication.Authenticator
|
auth *authentication.Authenticator
|
||||||
newLoginURL LoginURLProviderFunc
|
newLoginURL LoginURLProviderFunc
|
||||||
accts *accounts.Store
|
accts *accounts.Store
|
||||||
@@ -36,11 +38,13 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewAuth(
|
func NewAuth(
|
||||||
|
logger *slog.Logger,
|
||||||
auth *authentication.Authenticator,
|
auth *authentication.Authenticator,
|
||||||
newLoginURL LoginURLProviderFunc,
|
newLoginURL LoginURLProviderFunc,
|
||||||
accts *accounts.Store,
|
accts *accounts.Store,
|
||||||
) *Auth {
|
) *Auth {
|
||||||
return &Auth{
|
return &Auth{
|
||||||
|
log: logger,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
newLoginURL: newLoginURL,
|
newLoginURL: newLoginURL,
|
||||||
accts: accts,
|
accts: accts,
|
||||||
@@ -133,7 +137,7 @@ func (a *Auth) AuthenticateAndAddIdentity(f response.HandlerFunc, assertions ...
|
|||||||
if refreshFloor := expiration.Add(-(idTokenLifetime / 4)); refreshFloor.Before(now) {
|
if refreshFloor := expiration.Add(-(idTokenLifetime / 4)); refreshFloor.Before(now) {
|
||||||
accessToken, expiration, err = a.auth.RefreshAccessToken(ctx, accessToken)
|
accessToken, expiration, err = a.auth.RefreshAccessToken(ctx, accessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("failed to refresh access token:", err)
|
a.log.Warn("failed to refresh access token", "error", err)
|
||||||
return response.TemporaryRedirect("/").
|
return response.TemporaryRedirect("/").
|
||||||
Body(io.NopCloser(bytes.NewBuffer([]byte(fmt.Sprintf("failed to refresh access token: %v", err))))).
|
Body(io.NopCloser(bytes.NewBuffer([]byte(fmt.Sprintf("failed to refresh access token: %v", err))))).
|
||||||
Cookie(cookies.Expired("access_token")), nil
|
Cookie(cookies.Expired("access_token")), nil
|
||||||
|
|||||||
@@ -104,7 +104,9 @@ func NewServer(
|
|||||||
accts: accts,
|
accts: accts,
|
||||||
etsy: etsy,
|
etsy: etsy,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
|
// TODO: shouldn't this ACTUALLY be a middleware?
|
||||||
authMiddleware: middleware.NewAuth(
|
authMiddleware: middleware.NewAuth(
|
||||||
|
logger.WithGroup("auth-middleware"),
|
||||||
auth,
|
auth,
|
||||||
newLoginURL,
|
newLoginURL,
|
||||||
accts,
|
accts,
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func (h Webhooks) redirectURI(w http.ResponseWriter, r *http.Request) {
|
|||||||
ok, err := h.etsy.HandleNewAuthCode(ctx, acctID, state, q.Get("code"))
|
ok, err := h.etsy.HandleNewAuthCode(ctx, acctID, state, q.Get("code"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
fmt.Println("failed to handle new auth code:", err)
|
h.log.Error("failed to handle new auth code", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user