Esempio n. 1
0
func Authorize(db *database.Database, state string,
	code string) (acct *account.Account, tokn *oauth.Token, err error) {

	coll := db.Accounts()

	acct, tokn, err = conf.Authorize(db, state, code)
	if err != nil {
		return
	}

	client := &GoogleClient{
		acct: acct,
	}

	err = client.Update(db)
	if err != nil {
		return
	}

	_, err = coll.Upsert(&bson.M{
		"_id": acct.Id,
	}, acct)
	if err != nil {
		err = database.ParseError(err)
		return
	}

	return
}
Esempio n. 2
0
func (c *Oauth2Client) Refresh(db *database.Database) (err error) {
	refreshed, err := c.Check()
	if err != nil {
		return
	}

	if !refreshed {
		return
	}

	coll := db.Accounts()

	c.Account.Oauth2AccTokn = c.AccessToken
	c.Account.Oauth2RefTokn = c.RefreshToken
	c.Account.Oauth2Exp = c.Expiry

	if c.Account.Id == "" {
		return
	}

	fields := set.NewSet("oauth2_acc_tokn", "oauth2_ref_tokn", "oauth2_exp")

	err = coll.CommitFields(c.Account.Id, c.Account, fields)
	if err != nil {
		err = database.ParseError(err)
		return
	}

	return
}
Esempio n. 3
0
func Update(db *database.Database, user string) (err error) {
	coll := db.Accounts()

	acct := &account.Account{}

	err = coll.FindOneId(user, acct)
	if err != nil {
		return
	}

	client := &GoogleClient{
		acct: acct,
	}

	err = client.Update(db)
	if err != nil {
		return
	}

	_, err = coll.Upsert(&bson.M{
		"_id": acct.Id,
	}, acct)
	if err != nil {
		err = database.ParseError(err)
		return
	}

	return
}