Skip to content

Commit

Permalink
telegram header
Browse files Browse the repository at this point in the history
  • Loading branch information
ujuzy committed May 5, 2022
1 parent c4c20d9 commit 435d55e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
)

const (
UserKey = "X-Auth-User"
TokenKey = "X-Auth-Token"
UserKey = "X-Auth-User"
TokenKey = "X-Auth-Token"
TelegramKey = "X-Auth-Telegram"
)

type userInfo struct {
Expand Down Expand Up @@ -76,3 +77,17 @@ func GetUserInfo(ctx context.Context) (*userInfo, error) {

return &user, nil
}

func GetTelegramUsername(ctx context.Context) (string, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return "", status.Errorf(codes.InvalidArgument, "Retrieving metadata is failed")
}

tgHeader, ok := md[strings.ToLower(TelegramKey)]
if !ok {
return "", nil
}

return tgHeader[0], nil
}

0 comments on commit 435d55e

Please sign in to comment.