电报bot-OAuth授权
我想通过Twitch API在我的机器人上实现OAuth授权,当我在寻找更好的解决方案时,我发现了这个@GitHubBot。在这个bot重定向URL中,从integrations.telegram.org/github开始,我想知道如何像这样实现auth。若你们愿意,你们能告诉我在电报机器人程序中实现OAuth的最佳实践吗?哪种情况更好:授权码还是隐式授权?电报bot-OAuth授权,oauth,telegram-bot,Oauth,Telegram Bot,我想通过Twitch API在我的机器人上实现OAuth授权,当我在寻找更好的解决方案时,我发现了这个@GitHubBot。在这个bot重定向URL中,从integrations.telegram.org/github开始,我想知道如何像这样实现auth。若你们愿意,你们能告诉我在电报机器人程序中实现OAuth的最佳实践吗?哪种情况更好:授权码还是隐式授权? 提前谢谢你 我有同样的想法,授权通过电报访问第三方服务,我有两个主要想法。 灵感来源于: 第一个想法是创建具有唯一重定向URI的唯一授权
提前谢谢你 我有同样的想法,授权通过电报访问第三方服务,我有两个主要想法。 灵感来源于:
- 第一个想法是创建具有唯一重定向URI的唯一授权URL。 不幸的是,当我在谷歌控制台中设置凭据时,我错过了关于重定向URI的解释。上面说
- 第二种方法是访问资源,然后将哈希授权结果直接发送给bot。 预计会是这样的: ttps://telegram.me/bot?hashed_code=code 但是,不幸的是,我发现这也没有按计划进行。 我真的很失望这个事实,但经过一些偷偷摸摸,我发现通过直接URL向您的机器人传递参数的唯一方法是/start命令李>
最后,我成功地完成了用户授权-身份识别,但是在会话中间看到
code
参数start
。这在@evasyuk的回答中有很好的描述
我的解决方案是设置一个AWS API网关端点,该端点将从服务接收带有身份验证代码的回调,并使用start
参数将其重定向到bot的链接
我假设您有一个AWS帐户,但如果没有,则很容易创建,并且您可以免费使用此解决方案一年:
API网关免费层包括每月一百万次API调用,最长持续12个月
---
swagger: "2.0"
info:
version: "2017-02-25T14:22:32Z"
title: "BotAuthRedirect"
schemes:
- "https"
paths:
/:
x-amazon-apigateway-any-method:
produces:
- "text/html"
parameters:
- name: "code"
in: "query"
required: false
type: "string"
responses:
200:
description: "200 response"
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
type: "http"
httpMethod: "GET"
passthroughBehavior: "when_no_match"
responses:
default:
statusCode: "200"
requestParameters:
# This is where we map `code` query parameter to `start`
integration.request.querystring.start: "method.request.querystring.code"
# Don't forget to change your bot's username:
uri: "https://telegram.me/my_bot"
definitions:
Empty:
type: "object"
title: "Empty Schema"
https://<some_id>.execute-api.<region>.amazonaws.com/<stage>
https://abcdefghij.execute-api.eu-central-1.amazonaws.com/auth
https://some.service.com/auth?response_type=code&client_id=<your_client_id>&redirect_uri=https://abcdefghij.execute-api.eu-central-1.amazonaws.com
https://abcdefghij.execute-api.eu-central-1.amazonaws.com/auth?code=<auth_code>
https://telegram.me/my_bot?start=<auth_code>