对接钉钉登录

前提:

钉钉管理后台创建应用,添加个人信息接口权限,填写登录回调域名,即redirect_uri

方式一:钉钉扫码登录

index.html中的head标签中引入
<script src="https://g.alicdn.com/dingding/dinglogin/0.0.5/ddLogin.js"></script>

<template>
    <div id="dd-login" />
</template>
<script>
export default {
  mounted() {
    this.ddInit()
  },
  methods: {
    ddInit() {
      const appid = ''
      const url = encodeURIComponent('重定向的url')
      const goto = encodeURIComponent(`https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${url}`)
      window.DDLogin({
        id: 'dd-login',
        goto, //请参考注释里的方式
        style: 'border:none;background-color:#FFFFFF;',
        width: '100%',
        height: '300'
      });

      let handleMessage = (event) =>{
        let origin = event.origin;
        console.log("origin", event.origin);
        if (origin === "https://login.dingtalk.com") {
          //判断是否来自ddLogin扫码事件。
          const loginTmpCode = event.data;
          //获取到loginTmpCode后就可以在这里构造跳转链接进行跳转了
          console.log("loginTmpCode", loginTmpCode);
          window.location.href = `https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${appid}&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=${url}&loginTmpCode=${loginTmpCode}`;
        }
      };
      if (typeof window.addEventListener != 'undefined') {
        window.addEventListener('message', handleMessage, false);
      } else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent('onmessage', handleMessage);
      }
    },
  }
}
</script>

方式二:对接钉钉统一身份认证

redirect_uri:编码后的重定向地址

client_id:

  • 企业内部应用:client_id为应用的AppKey。

  • 第三方企业应用:client_id为应用的SuiteKey。

其他参数固定默认值

https://login.dingtalk.com/oauth2/challenge.htm?%20redirect_uri=&response_type=code%20&client_id=&scope=openid&state=dddd%20&prompt=consent&FEForceLogin=true

钉钉在url返回authCode,后台根据code获取个人信息

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值