Exemple #1
0
func ConfigKey(name string) []byte {
	config, err := conf.ReadConfigFile("config.ini")
	if err != nil {
		panic(err)
	}
	keyStr, err := config.GetString("encryption", name)
	if err != nil {
		panic(err)
	}
	key, err := hex.DecodeString(keyStr)
	if err != nil {
		panic(err)
	}
	return key
}
Exemple #2
0
func ReqTrustedClient(req *http.Request, success func(string) fhttp.Response) fhttp.Response {
	config, err := conf.ReadConfigFile("config.ini")
	if err != nil {
		panic(err)
	}
	clientId, err := config.GetString("webclient", "clientId")
	if err != nil {
		panic(err)
	}
	token := oauth2.DecodeToken(req)
	if token == nil || token.Client != clientId {
		return fhttp.UserError("invalid_token")
	}
	return success(token.User)
}
func newAuth(context appengine.Context) *Auth {
	client := urlfetch.Client(context)
	c, err := conf.ReadConfigFile("config.ini")
	if err != nil {
		panic(lib.ServerError{"could not read config file: " + err.String()})
	}
	username, err := c.GetString("rackspace", "username")
	if err != nil {
		panic(lib.ServerError{"could not read username: "******"rackspace", "key")
	if err != nil {
		panic(lib.ServerError{"could not read key: " + err.String()})
	}

	//  post an empty body
	req, err := http.NewRequest("GET", "https://auth.api.rackspacecloud.com/v1.0", nil)
	if err != nil {
		panic(lib.ServerError{"could not create request: " + err.String()})
	}
	req.Header.Add("x-Auth-Key", key)
	req.Header.Add("x-Auth-User", username)

	res, err := client.Do(req)
	if err != nil {
		panic(lib.ServerError{"problem contacting hosting provider: " + err.String()})
	}

	auth := Auth{res.Header.Get("X-Server-Management-Url"), res.Header.Get("X-Auth-Token")}
	err = memcache.Gob.Set(context, &memcache.Item{
		Key:    "rackspace-auth",
		Object: auth,
	})
	if err != nil {
		context.Warningf("could not write to memcache: %v", err.String())
	}
	return &auth
}