-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: auth to domain and handler to main
- Loading branch information
Showing
15 changed files
with
181 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package auth | ||
|
||
type ContextKey string | ||
|
||
const FirebaseAuthClientKey ContextKey = "firebaseAuthClient" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"firebase.google.com/go/auth" | ||
) | ||
|
||
type AuthService interface { | ||
VerifyAuth(ctx context.Context, authHeader string) (*auth.Token, error) | ||
CustomToken(ctx context.Context, uid string) (string, error) | ||
} | ||
|
||
type FirebaseBearerAuthService struct { | ||
authClient *auth.Client | ||
} | ||
|
||
func NewFirebaseBearerAuthService(authClient *auth.Client) *FirebaseBearerAuthService { | ||
return &FirebaseBearerAuthService{ | ||
authClient: authClient, | ||
} | ||
} | ||
|
||
func (s *FirebaseBearerAuthService) VerifyAuth(ctx context.Context, authHeader string) (*auth.Token, error) { | ||
idToken, err := s.stripBearerToken(authHeader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
authToken, err := s.authClient.VerifyIDToken(ctx, idToken) | ||
return authToken, err | ||
} | ||
|
||
func (s *FirebaseBearerAuthService) CustomToken(ctx context.Context, uid string) (string, error) { | ||
return s.authClient.CustomToken(ctx, uid) | ||
} | ||
|
||
func (s *FirebaseBearerAuthService) stripBearerToken(authHeader string) (string, error) { | ||
if len(authHeader) > 6 && strings.ToUpper(authHeader[0:7]) == "BEARER " { | ||
return authHeader[7:], nil | ||
} | ||
|
||
return authHeader, fmt.Errorf("invalid auth header") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package auth | ||
|
||
import "github.com/pet-sitter/pets-next-door-api/internal/domain/user" | ||
|
||
type KakaoCallbackResponse struct { | ||
AuthToken string `json:"authToken"` | ||
FirebaseProviderType user.FirebaseProviderType `json:"fbProviderType"` | ||
FirebaseUID string `json:"fbUid"` | ||
Email string `json:"email"` | ||
PhotoURL string `json:"photoURL"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.