// RequiredAuthTokens returns the authorization tokens required for the given endpoint and method.
RequiredAuthTokens returns the authorization tokens required for the given endpoint and method.
// RequiredAuthTokens returns the authorization tokens required for the given endpoint and method .
func (m *TokenManager) RequiredAuthTokens(endpoint, method string) ([]string, error) {
	var authTokens []string
	for _, def := range m.tokenDefs {
		ok := def.expr.MatchString(endpoint)
		if !ok {
			continue
		}
		var tokens []string
		switch method {
		case http.MethodGet:
			tokens = def.readTokens
		case http.MethodPost:
			tokens = def.writeTokens
		default:
			return nil, fmt.Errorf("unsupported HTTP method [%s]", method)
		}
		for _, tokenID := range tokens {
			token, ok := m.authTokens[tokenID]
			if !ok {
				return nil, fmt.Errorf("token not found: %s", tokenID)
			}
			authTokens = append(authTokens, token)
		}
		break
	}
	logger.Debugf("[%s] Authorization tokens required for %s: %s", endpoint, method, authTokens)
	return authTokens, nil
}
func ( m * TokenManager ) RequiredAuthTokens ( endpoint , method string ) ( [ ] string , error ) { var authTokens [ ] string for _ , def := range m . tokenDefs { ok := def . expr . MatchString ( endpoint ) if ! ok { continue } var tokens [ ] string switch method { case http . MethodGet : tokens = def . readTokens case http . MethodPost : tokens = def . writeTokens default : return nil , fmt . Errorf ( " " , method ) } for _ , tokenID := range tokens { token , ok := m . authTokens [ tokenID ] if ! ok { return nil , fmt . Errorf ( " " , tokenID ) } authTokens = append ( authTokens , token ) } break } logger . Debugf ( " " , endpoint , method , authTokens ) return authTokens , nil }
RequiredAuthTokens returns the authorization tokens required for the given endpoint and method.
RequiredAuthTokens returns the authorization tokens required for the given endpoint and method .