func (d *DefaultClient) CopyFrom(client osin.Client) {
	d.Id = client.GetId()
	d.Secret = client.GetSecret()
	d.RedirectUri = client.GetRedirectUri()
	d.UserData = nil
	//	d.UserData = client.GetUserData()
}
func (store *SQLStorage) SetClient(client osin.Client) error {
	stmt, err := store.authDB.Prepare("INSERT INTO clients(id, secret, redirect_uri, user_data) VALUES(?, ?, ?, ?)")

	// Marshal user data into string
	userDataStr, err := setUserData(client.GetUserData())
	if err != nil {
		return err
	}

	_, err = stmt.Exec(client.GetId(), client.GetSecret(), client.GetRedirectUri(), userDataStr)
	return err
}
Beispiel #3
0
func (s *MySQLStorage) SetClient(id string, client osin.Client) error {
	c := &osin.DefaultClient{
		Id:          client.GetId(),
		Secret:      client.GetSecret(),
		RedirectUri: client.GetRedirectUri(),
	}

	err := Transact(db.DB, func(tx *sql.Tx) error {
		var err error
		err = service.CreateClient(tx, c)
		return err
	})
	return err
}
// DeleteClient deletes given client
func (s *RethinkDBStorage) DeleteClient(c osin.Client) error {
	result, err := r.Table(clientsTable).Filter(r.Row.Field("Id").Eq(c.GetId())).Run(s.session)
	if err != nil {
		return err
	}
	defer result.Close()

	var clientMap map[string]interface{}
	err = result.One(&clientMap)
	if err != nil {
		return err
	}

	_, err = r.Table(clientsTable).Get(clientMap["id"]).Delete().RunWrite(s.session)
	return err
}
Beispiel #5
0
// CreateClient stores the client in the database and returns an error, if something went wrong.
func (s *Storage) CreateClient(c osin.Client) error {
	data, err := assertToString(c.GetUserData())
	if err != nil {
		return err
	}
	args := map[string]interface{}{
		"id":       c.GetId(),
		"secret":   c.GetSecret(),
		"redirect": c.GetRedirectUri(),
		"extra":    data,
	}
	nstmt, err := s.db.PrepareNamed("INSERT INTO client (id, secret, redirect_uri, extra) VALUES (:id, :secret, :redirect, :extra)")
	if err != nil {
		return errors.New(err)
	}
	_, err = nstmt.Exec(args)

	return nil
}
Beispiel #6
0
// UpdateClient update client with id c.GetId()
func (s *OAuth2Storage) UpdateClient(c osin.Client) (*OAuth2Client, error) {
	var numericID uint64
	var err error
	if numericID, err = strconv.ParseUint(c.GetId(), 10, 64); err != nil {
		return nil, fmt.Errorf("invalid client_id: %s", c.GetId())
	}

	client := OAuth2Client{
		ID:          numericID,
		RedirectURI: c.GetRedirectUri(),
		Secret:      c.GetSecret(),
		UserID:      c.GetUserData().(uint64),
	}

	if err := Db().Updates(&client); err != nil {
		return nil, err
	}

	return &client, nil
}
Beispiel #7
0
// UpdateClient updates the client (identified by it's id) and replaces the values with the values of client.
func (s *Storage) UpdateClient(c osin.Client) error {
	data, err := assertToString(c.GetUserData())
	if err != nil {
		return err
	}
	args := map[string]interface{}{
		"id":       c.GetId(),
		"secret":   c.GetSecret(),
		"redirect": c.GetRedirectUri(),
		"extra":    data,
	}

	nstmt, err := s.db.PrepareNamed("UPDATE client SET (secret, redirect_uri, extra) = (:secret, :redirect, :extra) WHERE idclient=:id")
	if err != nil {
		return err
	}
	_, err = nstmt.Exec(args)

	return nil
}
// CreateClient adds new client.
// This is not a part of interface and as so, it's never used in osin flow.
// However can be really usefull for applications to add new clients.
func (receiver *Storage) CreateClient(client osin.Client) error {
	data, err := json.Marshal(client)
	if err != nil {
		return err
	}

	params := &dynamodb.PutItemInput{
		Item: map[string]*dynamodb.AttributeValue{
			"id": {
				S: aws.String(client.GetId()),
			},
			"json": {
				S: aws.String(string(data)),
			},
		},
		TableName: aws.String(receiver.config.ClientTable),
	}

	if _, err := receiver.db.PutItem(params); err != nil {
		return err
	}

	return nil
}
Beispiel #9
0
func (store *SQLStorage) SetClient(client osin.Client) error {
	stmt, err := store.authDB.Prepare("INSERT INTO clients(id, secret, redirect_uri) VALUES(?, ?, ?)")

	_, err = stmt.Exec(client.GetId(), client.GetSecret(), client.GetRedirectUri())
	return err
}
Beispiel #10
0
func removeClient(t *testing.T, store storage.Storage, set osin.Client) {
	require.Nil(t, store.RemoveClient(set.GetId()))
}
Beispiel #11
0
func getClient(t *testing.T, store storage.Storage, set osin.Client) {
	client, err := store.GetClient(set.GetId())
	require.Nil(t, err)
	require.EqualValues(t, set, client)
}
Beispiel #12
0
// UpdateClient updates the client (identified by it's id) and replaces the values with the values of client.
func (s *Storage) UpdateClient(c osin.Client) error {
	data, err := assertToString(c.GetUserData())
	if err != nil {
		return err
	}

	if _, err := s.db.Exec("UPDATE client SET (secret, redirect_uri, extra) = ($2, $3, $4) WHERE id=$1", c.GetId(), c.GetSecret(), c.GetRedirectUri(), data); err != nil {
		return errors.New(err)
	}
	return nil
}
Beispiel #13
0
// CreateClient stores the client in the database and returns an error, if something went wrong.
func (s *Storage) CreateClient(c osin.Client) error {
	data, err := assertToString(c.GetUserData())
	if err != nil {
		return err
	}

	if _, err := s.db.Exec("INSERT INTO client (id, secret, redirect_uri, extra) VALUES ($1, $2, $3, $4)", c.GetId(), c.GetSecret(), c.GetRedirectUri(), data); err != nil {
		return errors.New(err)
	}
	return nil
}
Beispiel #14
0
func (s *Storage) CreateClient(c osin.Client) error {
	userData, err := dataToString(c.GetUserData())
	if err != nil {
		return err
	}
	_, err = s.db.Exec("INSERT INTO client (id, secret, redirect_uri, extra) VALUES ($1, $2, $3, $4)", c.GetId(), c.GetSecret(), c.GetRedirectUri(), userData)
	return err
}
Beispiel #15
0
func (s *Storage) UpdateClient(c osin.Client) error {
	userData, err := dataToString(c.GetUserData())
	if err != nil {
		return err
	}

	_, err = s.db.Exec("UPDATE client SET (secret, redirect_uri, extra) = ($2, $3, $4) WHERE id=$1", c.GetId(), c.GetSecret(), c.GetRedirectUri(), userData)
	return err
}