JWT token based auth

This commit is contained in:
David Zhao
2020-12-25 22:31:11 -08:00
parent 8f34bd6086
commit 804b7cb332
33 changed files with 1169 additions and 194 deletions
+111
View File
@@ -0,0 +1,111 @@
// Code generated by counterfeiter. DO NOT EDIT.
package authfakes
import (
"sync"
"github.com/livekit/livekit-server/pkg/auth"
)
type FakeKeyProvider struct {
GetSecretStub func(string) string
getSecretMutex sync.RWMutex
getSecretArgsForCall []struct {
arg1 string
}
getSecretReturns struct {
result1 string
}
getSecretReturnsOnCall map[int]struct {
result1 string
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *FakeKeyProvider) GetSecret(arg1 string) string {
fake.getSecretMutex.Lock()
ret, specificReturn := fake.getSecretReturnsOnCall[len(fake.getSecretArgsForCall)]
fake.getSecretArgsForCall = append(fake.getSecretArgsForCall, struct {
arg1 string
}{arg1})
stub := fake.GetSecretStub
fakeReturns := fake.getSecretReturns
fake.recordInvocation("GetSecret", []interface{}{arg1})
fake.getSecretMutex.Unlock()
if stub != nil {
return stub(arg1)
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeKeyProvider) GetSecretCallCount() int {
fake.getSecretMutex.RLock()
defer fake.getSecretMutex.RUnlock()
return len(fake.getSecretArgsForCall)
}
func (fake *FakeKeyProvider) GetSecretCalls(stub func(string) string) {
fake.getSecretMutex.Lock()
defer fake.getSecretMutex.Unlock()
fake.GetSecretStub = stub
}
func (fake *FakeKeyProvider) GetSecretArgsForCall(i int) string {
fake.getSecretMutex.RLock()
defer fake.getSecretMutex.RUnlock()
argsForCall := fake.getSecretArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeKeyProvider) GetSecretReturns(result1 string) {
fake.getSecretMutex.Lock()
defer fake.getSecretMutex.Unlock()
fake.GetSecretStub = nil
fake.getSecretReturns = struct {
result1 string
}{result1}
}
func (fake *FakeKeyProvider) GetSecretReturnsOnCall(i int, result1 string) {
fake.getSecretMutex.Lock()
defer fake.getSecretMutex.Unlock()
fake.GetSecretStub = nil
if fake.getSecretReturnsOnCall == nil {
fake.getSecretReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.getSecretReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *FakeKeyProvider) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.getSecretMutex.RLock()
defer fake.getSecretMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *FakeKeyProvider) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
var _ auth.KeyProvider = new(FakeKeyProvider)
+119
View File
@@ -0,0 +1,119 @@
// Code generated by counterfeiter. DO NOT EDIT.
package authfakes
import (
"sync"
"time"
"github.com/livekit/livekit-server/pkg/auth"
)
type FakeTokenIssuer struct {
CreateTokenStub func(*auth.GrantClaims, time.Duration) (string, error)
createTokenMutex sync.RWMutex
createTokenArgsForCall []struct {
arg1 *auth.GrantClaims
arg2 time.Duration
}
createTokenReturns struct {
result1 string
result2 error
}
createTokenReturnsOnCall map[int]struct {
result1 string
result2 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *FakeTokenIssuer) CreateToken(arg1 *auth.GrantClaims, arg2 time.Duration) (string, error) {
fake.createTokenMutex.Lock()
ret, specificReturn := fake.createTokenReturnsOnCall[len(fake.createTokenArgsForCall)]
fake.createTokenArgsForCall = append(fake.createTokenArgsForCall, struct {
arg1 *auth.GrantClaims
arg2 time.Duration
}{arg1, arg2})
stub := fake.CreateTokenStub
fakeReturns := fake.createTokenReturns
fake.recordInvocation("CreateToken", []interface{}{arg1, arg2})
fake.createTokenMutex.Unlock()
if stub != nil {
return stub(arg1, arg2)
}
if specificReturn {
return ret.result1, ret.result2
}
return fakeReturns.result1, fakeReturns.result2
}
func (fake *FakeTokenIssuer) CreateTokenCallCount() int {
fake.createTokenMutex.RLock()
defer fake.createTokenMutex.RUnlock()
return len(fake.createTokenArgsForCall)
}
func (fake *FakeTokenIssuer) CreateTokenCalls(stub func(*auth.GrantClaims, time.Duration) (string, error)) {
fake.createTokenMutex.Lock()
defer fake.createTokenMutex.Unlock()
fake.CreateTokenStub = stub
}
func (fake *FakeTokenIssuer) CreateTokenArgsForCall(i int) (*auth.GrantClaims, time.Duration) {
fake.createTokenMutex.RLock()
defer fake.createTokenMutex.RUnlock()
argsForCall := fake.createTokenArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *FakeTokenIssuer) CreateTokenReturns(result1 string, result2 error) {
fake.createTokenMutex.Lock()
defer fake.createTokenMutex.Unlock()
fake.CreateTokenStub = nil
fake.createTokenReturns = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *FakeTokenIssuer) CreateTokenReturnsOnCall(i int, result1 string, result2 error) {
fake.createTokenMutex.Lock()
defer fake.createTokenMutex.Unlock()
fake.CreateTokenStub = nil
if fake.createTokenReturnsOnCall == nil {
fake.createTokenReturnsOnCall = make(map[int]struct {
result1 string
result2 error
})
}
fake.createTokenReturnsOnCall[i] = struct {
result1 string
result2 error
}{result1, result2}
}
func (fake *FakeTokenIssuer) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.createTokenMutex.RLock()
defer fake.createTokenMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *FakeTokenIssuer) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
var _ auth.TokenIssuer = new(FakeTokenIssuer)
+107
View File
@@ -0,0 +1,107 @@
// Code generated by counterfeiter. DO NOT EDIT.
package authfakes
import (
"sync"
"github.com/livekit/livekit-server/pkg/auth"
)
type FakeTokenVerifier struct {
VerifyStub func() (*auth.GrantClaims, error)
verifyMutex sync.RWMutex
verifyArgsForCall []struct {
}
verifyReturns struct {
result1 *auth.GrantClaims
result2 error
}
verifyReturnsOnCall map[int]struct {
result1 *auth.GrantClaims
result2 error
}
invocations map[string][][]interface{}
invocationsMutex sync.RWMutex
}
func (fake *FakeTokenVerifier) Verify() (*auth.GrantClaims, error) {
fake.verifyMutex.Lock()
ret, specificReturn := fake.verifyReturnsOnCall[len(fake.verifyArgsForCall)]
fake.verifyArgsForCall = append(fake.verifyArgsForCall, struct {
}{})
stub := fake.VerifyStub
fakeReturns := fake.verifyReturns
fake.recordInvocation("Verify", []interface{}{})
fake.verifyMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1, ret.result2
}
return fakeReturns.result1, fakeReturns.result2
}
func (fake *FakeTokenVerifier) VerifyCallCount() int {
fake.verifyMutex.RLock()
defer fake.verifyMutex.RUnlock()
return len(fake.verifyArgsForCall)
}
func (fake *FakeTokenVerifier) VerifyCalls(stub func() (*auth.GrantClaims, error)) {
fake.verifyMutex.Lock()
defer fake.verifyMutex.Unlock()
fake.VerifyStub = stub
}
func (fake *FakeTokenVerifier) VerifyReturns(result1 *auth.GrantClaims, result2 error) {
fake.verifyMutex.Lock()
defer fake.verifyMutex.Unlock()
fake.VerifyStub = nil
fake.verifyReturns = struct {
result1 *auth.GrantClaims
result2 error
}{result1, result2}
}
func (fake *FakeTokenVerifier) VerifyReturnsOnCall(i int, result1 *auth.GrantClaims, result2 error) {
fake.verifyMutex.Lock()
defer fake.verifyMutex.Unlock()
fake.VerifyStub = nil
if fake.verifyReturnsOnCall == nil {
fake.verifyReturnsOnCall = make(map[int]struct {
result1 *auth.GrantClaims
result2 error
})
}
fake.verifyReturnsOnCall[i] = struct {
result1 *auth.GrantClaims
result2 error
}{result1, result2}
}
func (fake *FakeTokenVerifier) Invocations() map[string][][]interface{} {
fake.invocationsMutex.RLock()
defer fake.invocationsMutex.RUnlock()
fake.verifyMutex.RLock()
defer fake.verifyMutex.RUnlock()
copiedInvocations := map[string][][]interface{}{}
for key, value := range fake.invocations {
copiedInvocations[key] = value
}
return copiedInvocations
}
func (fake *FakeTokenVerifier) recordInvocation(key string, args []interface{}) {
fake.invocationsMutex.Lock()
defer fake.invocationsMutex.Unlock()
if fake.invocations == nil {
fake.invocations = map[string][][]interface{}{}
}
if fake.invocations[key] == nil {
fake.invocations[key] = [][]interface{}{}
}
fake.invocations[key] = append(fake.invocations[key], args)
}
var _ auth.TokenVerifier = new(FakeTokenVerifier)