Skip to content
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

Implement Telegram provider #68

Merged
merged 20 commits into from
Oct 16, 2020
Merged

Implement Telegram provider #68

merged 20 commits into from
Oct 16, 2020

Conversation

holykol
Copy link
Contributor

@holykol holykol commented Oct 3, 2020

This PR adds Telegram as a login provider. The new flow uses deep-linking (see official example) to establish user identity.
Here are the steps:

  1. User clicks link that opens up chat with login bot in local Telegram client
  2. User presses 'Start' button which silently sends us some well-known value
  3. The page magically logs user in (thanks to client-side polling)

TODO:

  • Tests
  • Downloading user avatars
  • Auth request eviction

Closes #49

@holykol holykol requested a review from umputun as a code owner October 3, 2020 00:06
@coveralls
Copy link

coveralls commented Oct 3, 2020

Pull Request Test Coverage Report for Build 306194037

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 94.527%

Files with Coverage Reduction New Missed Lines %
auth.go 11 94.53%
Totals Coverage Status
Change from base Build 211748441: 0.03%
Covered Lines: 190
Relevant Lines: 201

💛 - Coveralls

* Separate Telegram API methods into their own interface
*  Test TelegramHandler and TelegramAPI independently
* Update usage example
Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the PR. The code is clean, easy to read, and probably does the right thing (I have not tried to run an example yet). I've added some (mostly minor) things to address. And another missing part - some documentation in the README about tg providers.

provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram.go Outdated Show resolved Hide resolved
provider/telegram_test.go Outdated Show resolved Hide resolved
@holykol
Copy link
Contributor Author

holykol commented Oct 11, 2020

@umputun Thanks for the feedback! I've fixed things that you have mentioned and added some documentation for the feature (although I'm not sure if it is good enough).

@holykol holykol requested a review from umputun October 11, 2020 20:56
@umputun
Copy link
Member

umputun commented Oct 12, 2020

I have tried to run _example but can't get it to work. Tried to follow the instruction, i.e. registred a new bot, got the token, passed it in, i.e. TELEGRAM_TOKEN="xxxxxx" go run main.go --dbg. After hitting start in tg client nothing good happens in the example app, all I see in log is 404 - GET - /auth/telegram/login?token=******** - [] - 404 (38) - 34.997µs

* Fetch bot username on Handler initialization
* _example: Do not run tg provider when token is not supplied
* Fix docs to reflect changes
@holykol
Copy link
Contributor Author

holykol commented Oct 13, 2020

@umputun My bad. The bot username in _example was hardcoded, so you were probably sending start command to the wrong bot. Pushing a fix RN.

@umputun
Copy link
Member

umputun commented Oct 13, 2020

thx, worked

@umputun
Copy link
Member

umputun commented Oct 13, 2020

how about this issue?

as soon as user logged out, it starts to send those, constantly:

2020/10/13 17:32:48.863 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 26.34µs
2020/10/13 17:32:49.864 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 43.622µs
2020/10/13 17:32:50.863 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 35.893µs
2020/10/13 17:32:51.864 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 30.566µs
2020/10/13 17:32:52.865 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 76.823µs
2020/10/13 17:32:53.868 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 101.266µs
2020/10/13 17:32:55.872 [INFO]  {logger/logger.go:122 logger.(*Middleware).Handler.func1.1} GET - /auth/telegram/login?token=******** - [] - 404 (38) - 106.877µs

@holykol
Copy link
Contributor Author

holykol commented Oct 14, 2020

Fixed. The requests are now made only after link is clicked to avoid polluting logs.

@umputun
Copy link
Member

umputun commented Oct 16, 2020

LGTM, thx

@umputun umputun merged commit 4ac50df into go-pkgz:master Oct 16, 2020
@holykol
Copy link
Contributor Author

holykol commented Oct 16, 2020

Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Telegram Login
3 participants