我们今天来说一下authentication,authentication一直是一个复杂的问题。bot里的authentication也不简单。我们先来看一个概念:Bot Framework Token Service,根据官方定义,这个token service主要是:
- Facilitating the use of the OAuth protocol with a wide variety of external services.
- Securely storing tokens for a particular bot, channel, conversation, and user.
- Acquiring user tokens
可以看到这个service会和外部的服务沟通,保存一些已经获取的token,这样下次再来申请token的时候Bot Framework Token Service可以返回已经保存的token。
我们以一个例子来看一下具体的做法:
假设用户促发了一个操作,要完成这个操作需要我们的bot调用Graph API,而调用Graph API需要有调用的Token。
-
用户促发了一个email请求操作
-
这个操作作为一个activity被发送给了Bot Framework channel service,后者把这个请求进一步发送给了我们的bot服务。
-
我们的bot service发现用户的activity需要一个访问Graph API的token,所以就问Token Service