Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'IsInTeams' does not recognized from ios and android teams app - dotnet-sdk #4365

Closed
georgemichailou opened this issue Mar 23, 2022 · 3 comments
Assignees
Labels

Comments

@georgemichailou
Copy link

georgemichailou commented Mar 23, 2022

Describe the bug
When I run my app from android or ios teams application the IsInTeams method returns false and GetUserInfo is not working.

protected override string ModulePath => "./js/TeamsJsBlazorInterop.js";

export function inTeams() { var microsoftTeamsLib = microsoftTeams || window["microsoftTeams"]; return window.self !== window.top && microsoftTeamsLib !== undefined; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if (firstRender)
        {
            isInTeams = await MicrosoftTeams.IsInTeams();

            if (isInTeams)
            {
                var user = await teamsUserCredential.GetUserInfoAsync();
                userName = user.DisplayName;
                preferredUserName = user.PreferredUserName;
            }
            else
            {
                errorMessage = "Not running in Microsoft Teams.";
            }

            isLoading = false;
            StateHasChanged();
        }
    }

*VS Information
Version Visual Studio Enterprise 2022
Microsoft Teams development tools

image

@ghost
Copy link

ghost commented Mar 23, 2022

Thank you for contacting us! Any issue or feedback from you is quite important to us. We will do our best to fully respond to your issue as soon as possible. Sometimes additional investigations may be needed, we will usually get back to you within 2 days by adding comments to this issue. Please stay tuned.

@tecton
Copy link
Contributor

tecton commented Mar 24, 2022

Hi @georgemichailou, thanks for reporting this issue.
Please replace the inTeams function in js/TeamsJsBlazorInterop.js with the following snippet:

export function inTeams() {
    if (
        (window.parent === window.self && window.nativeInterface) ||
        window.navigator.userAgent.includes("Teams/") ||
        window.name === "embedded-page-container" ||
        window.name === "extension-tab-frame"
    ) {
        return true;
    }
    return false;
}

@georgemichailou
Copy link
Author

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants