[#106] Pass bearer token through generated requests
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
e6f04f7785
commit
ae0dd9e051
8 changed files with 32 additions and 3 deletions
|
@ -8,7 +8,8 @@ import (
|
|||
type CommonPrm struct {
|
||||
local bool
|
||||
|
||||
token *token.SessionToken
|
||||
token *token.SessionToken
|
||||
bearer *token.BearerToken
|
||||
}
|
||||
|
||||
func (p *CommonPrm) WithLocalOnly(v bool) *CommonPrm {
|
||||
|
@ -35,6 +36,14 @@ func (p *CommonPrm) WithSessionToken(token *token.SessionToken) *CommonPrm {
|
|||
return p
|
||||
}
|
||||
|
||||
func (p *CommonPrm) WithBearerToken(token *token.BearerToken) *CommonPrm {
|
||||
if p != nil {
|
||||
p.bearer = token
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *CommonPrm) SessionToken() *token.SessionToken {
|
||||
if p != nil {
|
||||
return p.token
|
||||
|
@ -43,13 +52,22 @@ func (p *CommonPrm) SessionToken() *token.SessionToken {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *CommonPrm) BearerToken() *token.BearerToken {
|
||||
if p != nil {
|
||||
return p.bearer
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CommonPrmFromV2(req interface {
|
||||
GetMetaHeader() *session.RequestMetaHeader
|
||||
}) *CommonPrm {
|
||||
meta := req.GetMetaHeader()
|
||||
|
||||
return &CommonPrm{
|
||||
local: meta.GetTTL() <= 1, // FIXME: use constant
|
||||
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
|
||||
local: meta.GetTTL() <= 1, // FIXME: use constant
|
||||
token: token.NewSessionTokenFromV2(meta.GetSessionToken()),
|
||||
bearer: token.NewBearerTokenFromV2(meta.GetBearerToken()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue