package auth import ( "fmt" "math/rand" "github.com/spf13/viper" "golang.org/x/oauth2" ) var ( letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") stateRand *rand.Rand googleConfig oauth2.Config ) func Init(v *viper.Viper) { googleConfig = oauth2.Config{ // ClientID: "141386065809-og78kt5um5kdtstvlk7m8e00231aadgi.apps.googleusercontent.com", ClientID: v.GetString("auth.google.client_id"), // ClientSecret: "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", ClientSecret: v.GetString("auth.google.client_secret"), // RedirectURL: "http://localhost:9000/v1/health/callback", RedirectURL: fmt.Sprintf("%s%s", v.GetString("redirect_url"), v.GetString("auth.google.redirect_uri")), Scopes: []string{"openid email profile"}, Endpoint: oauth2.Endpoint{ AuthURL: "https://accounts.google.com/o/oauth2/v2/auth", TokenURL: "https://www.googleapis.com/oauth2/v4/token", }, } } // RandToken Generate a random token func GenerateOauthState() string { l := len(letterRunes) b := make([]rune, 24) for i := range b { b[i] = letterRunes[stateRand.Intn(l)] } return string(b) }