Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中获取Microsoft Teams用户的身份验证令牌?(How to get Authentication Token of Microsoft Teams User in JavaScript?)

I'm trying to get the current Auth Token of the logged in MS Teams user.

(我正在尝试获取登录的MS Teams用户的当前身份验证令牌。)

So that I can use the data for a different login that is inside the iframe of my website tab.

(这样我就可以将数据用于“网站”标签的iframe中的其他登录。)

So far I know, that the token is stored in localStorage of my browser.

(到目前为止,我知道令牌已存储在浏览器的localStorage中。)

I've already implemented the Microsoft Team SDK in my project.

(我已经在项目中实现了Microsoft Team SDK。)

I use the getAuthToken function expecting to get the current token, but it gives an error

(我使用了getAuthToken函数,希望获得当前令牌,但是它给出了一个错误)

"TypeError: e is undefined" .

(“ TypeError:e未定义”。)

So, how do I get the cached token of my MS Teams user from my localStorage and how do I request a new one if it's expired?

(因此,如何从localStorage获取MS Teams用户的缓存令牌,以及如果过期则如何请求新令牌?)

Code snippet :

(程式码片段:)

<template>
  <div>
    <button v-on:click="getAuth()">do</button>
  </div>
</template>

<script>
import * as microsoftTeams from "@microsoft/teams-js";

export default {
  data() {
    return {
      microsoftTeams,
      token: ""
    };
  },
  methods: {
    getAuth() {
      this.microsoftTeams.initialize();
      this.token = this.microsoftTeams.authentication.getAuthToken();
      console.log(this.token);
    }
  }
};
</script>

Edit 2019-11-28:

(编辑2019-11-28:)

Apparently the getAuthToken functions requires a AuthTokenRequest object.

(显然, getAuthToken函数需要AuthTokenRequest对象。)

So far I couldn't figure out, how to create one.

(到目前为止,我还不知道如何创建一个。)

Edit 2019-11-29: getAuthToken seems to be a none working function.

(编辑2019-11-29: getAuthToken似乎是一个getAuthToken函数。)

I currently trying to make it work with the adal package.

(我目前正在尝试使其与adal包一起使用。)

  ask by JtotheW translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...