-
-
Notifications
You must be signed in to change notification settings - Fork 160
qrlogin: fix Export method to handle all AuthExportLoginToken response types #1571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d4dd09e
7e2b58c
9f81eb6
6ab914d
d1e32a1
2fd1d02
a219bea
4c22747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"cSpell.words": [ | ||
"APIID", | ||
"DCID", | ||
"gotd", | ||
"qrlogin", | ||
"stretchr", | ||
"testutil", | ||
"tgmock" | ||
], | ||
"cSpell.language": "en, en-US" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,21 @@ func (q QR) Export(ctx context.Context, exceptIDs ...int64) (Token, error) { | |
return Token{}, errors.Wrap(err, "export") | ||
} | ||
|
||
t, ok := result.(*tg.AuthLoginToken) | ||
if !ok { | ||
switch t := result.(type) { | ||
case *tg.AuthLoginToken: | ||
return NewToken(t.Token, t.Expires), nil | ||
case *tg.AuthLoginTokenSuccess: | ||
// Token was already accepted, authentication successful | ||
// Return empty token since no new token is needed | ||
return Token{}, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
case *tg.AuthLoginTokenMigrateTo: | ||
// Migration needed | ||
return Token{}, &MigrationNeededError{ | ||
MigrateTo: t, | ||
} | ||
default: | ||
return Token{}, errors.Errorf("unexpected type %T", result) | ||
} | ||
return NewToken(t.Token, t.Expires), nil | ||
} | ||
|
||
// Accept accepts given token. | ||
|
@@ -147,6 +157,18 @@ func (q QR) Auth( | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// If token is empty, it means AuthLoginTokenSuccess was returned | ||
// and authentication is already complete, but we should wait for the signal | ||
if token.String() == "" { | ||
select { | ||
case <-ctx.Done(): | ||
return nil, ctx.Err() | ||
case <-loggedIn: | ||
return q.Import(ctx) | ||
} | ||
} | ||
|
||
timer := q.clock.Timer(until(token)) | ||
defer clock.StopTimer(timer) | ||
|
||
|
@@ -163,6 +185,13 @@ func (q QR) Auth( | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// If empty token, it means AuthLoginTokenSuccess was returned | ||
if t.String() == "" { | ||
// QR was scanned and accepted, break out of loop | ||
break | ||
} | ||
Comment on lines
+189
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This The logic itself seems fine to me, but comment should be fixed. |
||
|
||
token = t | ||
timer.Reset(until(token)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this error is unused.