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 }
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 }
// 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 }
// 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 }
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 }
// CreateClient creates a new OAuth2 Client func (s *OAuth2Storage) CreateClient(c osin.Client, name string) (*OAuth2Client, error) { client := OAuth2Client{ Name: name, RedirectURI: c.GetRedirectUri(), Secret: c.GetSecret(), UserID: c.GetUserData().(uint64), } if err := Db().Create(&client); err != nil { return nil, err } return &client, nil }
// 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 }
// 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 }
// 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 }