-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.go
45 lines (34 loc) · 1.19 KB
/
auth.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
package firebase
import (
"context"
"fmt"
"firebase.google.com/go/v4/auth"
"github.com/opentracing/opentracing-go"
)
func (a *admin) VerifyIDToken(ctx context.Context, idToken string) (*auth.Token, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "repository.VerifyIDToken")
defer span.Finish()
token, err := a.authClient.VerifyIDToken(ctx, idToken)
if err != nil {
return nil, fmt.Errorf("failed to call firebase sdk: %w", err)
}
return token, nil
}
func (a *admin) CreateSession(ctx context.Context, idToken string) (string, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "repository.CreateSession")
defer span.Finish()
cookie, err := a.authClient.SessionCookie(ctx, idToken, a.sessionLifetime)
if err != nil {
return "", fmt.Errorf("failed to call firebase sdk: %w", err)
}
return cookie, nil
}
func (a *admin) VerifySessionCookie(ctx context.Context, cookie string) (*auth.Token, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "repository.VerifySessionCookie")
defer span.Finish()
token, err := a.authClient.VerifySessionCookie(ctx, cookie)
if err != nil {
return nil, fmt.Errorf("failed to call firebase sdk: %w", err)
}
return token, nil
}