<commit_before>// Package auth provides an interface to authenticate user against the api.
package auth

import (
	"crypto/rand"
	"encoding/base64"
	"fmt"
	"strings"
	"time"

	"github.com/backstage/backstage/account"
	"github.com/backstage/backstage/db"
	. "github.com/backstage/backstage/errors"
	"github.com/fatih/structs"
)

const (
	ExpiresInSeconds  = 24 * 3600
	ExpiresTokenCache = ExpiresInSeconds - 10 // time in seconds to remove from expire time.
	TokenType         = "Token"
)

type Token interface {
	GetUserFromToken(auth string) (user *account.User, error error)
	TokenFor(user *account.User) *TokenInfo
	RevokeTokensFor(user *account.User)
	GenerateToken(user *account.User) *TokenInfo
}

type TokenInfo struct {
	Token     string `json:"token"`
	Type      string `json:"token_type"`
	Expires   int    `json:"expires"`
	CreatedAt string `bson:"created_at" json:"created_at"`
}

// Convert a Token in a user.
// Given a token, find the user.
func GetUserFromToken(auth string) (user *account.User, error error) {
	var (
		tt       string
		tokenKey string
	)<commit_msg>Rename token info to access_token.<commit_after>// Package auth provides an interface to authenticate user against the api.
package auth

import (
	"crypto/rand"
	"encoding/base64"
	"fmt"
	"strings"
	"time"

	"github.com/backstage/backstage/account"
	"github.com/backstage/backstage/db"
	. "github.com/backstage/backstage/errors"
	"github.com/fatih/structs"
)

const (
	ExpiresInSeconds  = 24 * 3600
	ExpiresTokenCache = ExpiresInSeconds - 10 // time in seconds to remove from expire time.
	TokenType         = "Token"
)

type Token interface {
	GetUserFromToken(auth string) (user *account.User, error error)
	TokenFor(user *account.User) *TokenInfo
	RevokeTokensFor(user *account.User)
	GenerateToken(user *account.User) *TokenInfo
}

type TokenInfo struct {
	Token     string `json:"access_token"`
	Type      string `json:"token_type"`
	Expires   int    `json:"expires"`
	CreatedAt string `bson:"created_at" json:"created_at"`
}

// Convert a Token in a user.
// Given a token, find the user.
func GetUserFromToken(auth string) (user *account.User, error error) {
	var (
		tt       string
		tokenKey string
	)
{'fraction_non_alphanumeric': 0.11065573770491803, 'fraction_numerical': 0.009107468123861567, 'mean_word_length': 4.06221198156682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2701511', 'n_tokens_mistral': 758, 'n_tokens_neox': 730, 'n_words': 200}