@@ -2,7 +2,6 @@ package main
22
33import (
44 "context"
5- "encoding/json"
65 "flag"
76 "fmt"
87 "io"
@@ -14,8 +13,6 @@ import (
1413 "github.com/sourcegraph/src-cli/internal/cmderrors"
1514 "github.com/sourcegraph/src-cli/internal/keyring"
1615 "github.com/sourcegraph/src-cli/internal/oauthdevice"
17-
18- "github.com/sourcegraph/sourcegraph/lib/errors"
1916)
2017
2118func init () {
@@ -137,14 +134,14 @@ func loginCmd(ctx context.Context, p loginParams) error {
137134 cfg .Endpoint = endpointArg
138135
139136 if p .useDeviceFlow {
140- resp , err := runDeviceFlow (ctx , endpointArg , out , p .deviceFlowClient )
137+ token , err := runDeviceFlow (ctx , endpointArg , out , p .deviceFlowClient )
141138 if err != nil {
142139 printProblem (fmt .Sprintf ("Device flow authentication failed: %s" , err ))
143140 fmt .Fprintln (out , createAccessTokenMessage )
144141 return cmderrors .ExitCode1
145142 }
146143
147- if err := oauthdevice .StoreToken (secretStore , & resp . Token ); err != nil {
144+ if err := oauthdevice .StoreToken (secretStore , token ); err != nil {
148145 printProblem (fmt .Sprintf ("Failed to store token in keyring store: %s" , err ))
149146 return cmderrors .ExitCode1
150147 }
@@ -198,10 +195,7 @@ func loginCmd(ctx context.Context, p loginParams) error {
198195 return nil
199196}
200197
201- func storeToken (store * keyring.Store , token * oauthdevice.Token ) error {
202- }
203-
204- func runDeviceFlow (ctx context.Context , endpoint string , out io.Writer , client oauthdevice.Client ) (* oauthdevice.TokenResponse , error ) {
198+ func runDeviceFlow (ctx context.Context , endpoint string , out io.Writer , client oauthdevice.Client ) (* oauthdevice.Token , error ) {
205199 authResp , err := client .Start (ctx , endpoint , nil )
206200 if err != nil {
207201 return nil , err
@@ -222,10 +216,10 @@ func runDeviceFlow(ctx context.Context, endpoint string, out io.Writer, client o
222216 interval = 5 * time .Second
223217 }
224218
225- tokenResp , err := client .Poll (ctx , endpoint , authResp .DeviceCode , interval , authResp .ExpiresIn )
219+ resp , err := client .Poll (ctx , endpoint , authResp .DeviceCode , interval , authResp .ExpiresIn )
226220 if err != nil {
227221 return nil , err
228222 }
229223
230- return tokenResp , nil
224+ return resp . Token ( endpoint ) , nil
231225}
0 commit comments