Getting Consent Failure error in my app during Microsoft Teams SSO authentication

I have an app on Microsoft Teams that can be installed as a Tab in a teams channel. It is using Teams’s SSO authentication. When a new user (a user who has never consented to use certain account info to the app) opens the app, it asks for consenting some MS Graph API permissions. But the process is always failing while asking this consent and throwing an error. But after that if I reload the tab, then the authentication is successful. Hence, the consent process is working, but somehow it is not reflecting in the app immediately.

This issue is happening after updating the Microsoft Teams SDK for JavaScript to version 2. In version 1 there was no error and users were able to provide consent successfully and login.
After upgrading to version 2 of the SDK, the existing users can access the app and login to it normally. But for new users, the authentication is always failing at the consent stage and they have to reload the app once after consenting.

Following is the code for asking the consent.

  • If a consent is required, then the app is showing a screen with Next button. On click of this button the following function is executed.
showConsentDialog() {
    console.log(window.location.origin);

    microsoftTeams.authentication
      .authenticate({
        url: window.location.origin + "/auth-start",
        width: 600,
        height: 535,
      })
      .then((result) => {
        console.log("Success Callback");
        console.log({ result });
        this.consentSuccess(result);
      })
      .catch((reason) => {
        this.consentFailure(reason);
      });
  }

  //Callback function for a successful authorization
  consentSuccess(result) {
    console.log("Consent Success");
    console.log({ result });
    //Save the Graph access token in state
    this.setState({
      graphAccessToken: result["access_token"],
      graphRefreshtoken: result["refresh_token"],
      consentProvided: true,
    });
    // backend API call to login the user
    this.exchangeClientTokenForServerTokenAfterConsentSuccess(
      result["access_token"],
      result["refresh_token"]
    );
  }

  consentFailure(reason) {
    console.error("Consent failed: ", reason);
    this.setState({ error: true });
    // this.showConsentDialog(); //Proceed to show the consent dialogue. commented because of the showConsent screen developed for user interaction needed when popup is blocked from browser setting
  }
  • In the showConsentDialog() function, the popup for consent is opening fine, but the code is always moving to the catch block instaed of the then block.

  • For existing users, who have already consented earlier, the authentication is being successful at the first stage of getting authToken using microsoftTeams.authentication.getAuthToken() and it is not coming to this showConsentDialog() function, hence there is no issue on that scenario.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật