Skip to content

Commit

Permalink
Get token from auth and bugfix for getAll
Browse files Browse the repository at this point in the history
  • Loading branch information
firstthumb committed Jun 13, 2021
1 parent 6bda6f3 commit 78a61d5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 6 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (

type Authenticator struct {
config *oauth2.Config
token *oauth2.Token
context context.Context
}

Expand Down Expand Up @@ -67,6 +68,10 @@ func (a *Authenticator) AuthURLWithOpts(state string, opts ...oauth2.AuthCodeOpt
return a.config.AuthCodeURL(state, opts...)
}

func (a *Authenticator) GetToken() *oauth2.Token {
return a.token
}

func (a *Authenticator) Token(state string, r *http.Request) (*oauth2.Token, error) {
values := r.URL.Query()
if e := values.Get("error"); e != "" {
Expand Down Expand Up @@ -129,6 +134,7 @@ func (a *Authenticator) Authenticate() (*Client, error) {

select {
case token = <-tokenCh:
a.token = token
client = a.NewClient(token)
return client, nil

Expand Down
10 changes: 0 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ func NewClient(host, clientId string, opts *ClientOptions) *Client {
return c
}

func NewClientRemote(opts *ClientOptions) *Client {
c, err := newClient("https://api.meethue.com/v2/", opts)
if err != nil {
c.logger.Error(err, "Couldn't create client")
return nil
}

return c
}

// CreateUser creates local user on the bridge and returns authenticated client instance
// Don't forget to press bridge button otherwise it will fail
func CreateUser(host, deviceType string, opts *ClientOptions) (*Client, error) {
Expand Down
1 change: 1 addition & 0 deletions light.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *LightService) GetAll(ctx context.Context) ([]Light, *Response, error) {
for k, l := range lights {
id, _ := strconv.Atoi(k)
l.ID = id
lights[k] = l
}

return funk.Values(lights).([]Light), resp, nil
Expand Down

0 comments on commit 78a61d5

Please sign in to comment.