Esempio n. 1
0
func (self *SessionController) SignIn(c *gin.Context) {
	state, err := util.GenerateRandomString()

	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.String(http.StatusBadRequest, "Failed to generate state string.", err)
		return
	}

	session := sessions.Default(c)
	session.Set("state", state)
	session.Save()

	url := self.oauthConf.AuthCodeURL(state, oauth2.AccessTypeOnline)
	c.Redirect(http.StatusSeeOther, url)
}
Esempio n. 2
0
func LoadConfig() (*Config, error) {
	var config Config

	err := envconfig.Process(ConfigPrefix, &config)

	if err != nil {
		return nil, errors.Wrap(err, "Failed to load config from envs.")
	}

	if config.SecretKeyBase == "" {
		s, err := util.GenerateRandomString()

		if err != nil {
			return nil, err
		}

		config.SecretKeyBase = s
	}

	return &config, nil
}