学校网站建设情况汇报,做网站会员金字塔系统,网站a记录吗,企业做淘宝网站需要多少钱我们今天来说一下authentication#xff0c;authentication一直是一个复杂的问题。bot里的authentication也不简单。我们先来看一个概念#xff1a;Bot Framework Token Service#xff0c;根据官方定义#xff0c;这个token service主要是#xff1a; Facilitating the u…我们今天来说一下authenticationauthentication一直是一个复杂的问题。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请求这个token 由于这是此用户第一次发起这个请求Bot Framework Token Service之前没有保存过这用户的token所以它返回给我们bot说没有找到token。 bot会为了获取token需要用户确认授权所以bot创建了一个OAuthCard对象并且含有GraphConnection的名字并且把这个OAuthCard穿回Channel Service Bot Framework Channel Service收到这么一个请求后就会调用Bot Framework Token Service来获取一个合法的OAuth登入网址。这个登入网址会被加入到OAuthCard对象 Bot Framework Channel Service将含有OAuth登入网址的OAuthCard对象发送回用户这个对象会有一个sign-in的按钮。 用户收到OAuthCard对象点击上面的登入按钮聊天客户端会打开用户登入的网页让用户登入。 在用户登入授权后外部的Identity Provider就会把token传回给Bot Framework Token ServiceBot Framework Token Service则会安全地把token保存下来。 我们的bot收到token后就可以对Graph API发起请求了。
等到下一次如果我们bot又需要同一个用户的token时Bot Framework Token Service会从TokenStore里找到之前保存的token如果token还没有过期的话就直接返回给bot了。
authentication实际上是一个十分庞大复杂的topic有兴趣的读者还可以参考 这篇文档