# @mattbillfred/mgt-teamsfx-provider

> The Microsoft Graph Toolkit TeamsFx Provider

Latest version **3.1.3-next.mgt-chat.a661926e2** (published 2024-01-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mattbillfred/mgt-teamsfx-provider
pnpm add @mattbillfred/mgt-teamsfx-provider
yarn add @mattbillfred/mgt-teamsfx-provider
bun add @mattbillfred/mgt-teamsfx-provider
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.3-next.mgt-chat.a661926e2 |
| Published | 2024-01-23 |
| First published | 2024-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 96.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1066 |
| Author | Microsoft |
| Maintainers | mattbillfred |
| Keywords | microsoft graph, microsoft graph toolkit, mgt, msal, auth, msal 2.0, teamsfx, authentication |

## Links

- npm: https://www.npmjs.com/package/@mattbillfred/mgt-teamsfx-provider
- Repository: https://github.com/microsoftgraph/microsoft-graph-toolkit
- Issues: https://github.com/microsoftgraph/microsoft-graph-toolkit/issues
- npm.io page: https://npm.io/package/@mattbillfred/mgt-teamsfx-provider

## Dependencies (2)

- [@azure/core-auth](https://npm.io/package/@azure/core-auth.md) ^1.3.0
- [@microsoft/mgt-element](https://npm.io/package/@microsoft/mgt-element.md) npm:@mattbillfred/mgt-element@3.1.3-next.mgt-chat.a661926e2

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 3.1.3-next.mgt-chat.a661926e2 (latest) — 2024-01-23
- 4.0.0-next.mgt-chat.c717e60ac (next.mgt-chat) — 2024-08-27
- 4.0.0-next.mgt-chat.fc24d3d41 — 2024-08-14
- 4.0.0-next.mgt-chat.79d5befff — 2024-06-26
- 4.0.0-next.mgt-chat.cc1ea0ea6 — 2024-03-07
- 4.0.0-next.mgt-chat.fee25d1c3 — 2024-03-07
- 4.0.0-next.mgt-chat.129ad4ddf — 2024-03-06
- 4.0.0-next.mgt-chat.39697865a — 2024-03-01
- 4.0.0-next.mgt-chat.dee9cd5ff — 2024-03-01
- 4.0.0-next.mgt-chat.457f61d74 — 2024-03-01
- 4.0.0-next.mgt-chat.ec95d3c9f — 2024-02-28
- 4.0.0-next.mgt-chat.656ff3d30 — 2024-02-26
- 4.0.0-next.mgt-chat.79746f233 — 2024-02-23
- 4.0.0-next.mgt-chat.50211e4d8 — 2024-02-20
- 4.0.0-next.mgt-chat.837b7cbf4 — 2024-02-19
- … 17 more at https://npm.io/package/@mattbillfred/mgt-teamsfx-provider/versions

## README

# Microsoft Graph Toolkit TeamsFx Provider

[![npm](https://img.shields.io/npm/v/@microsoft/mgt-teamsfx-provider?style=for-the-badge)](https://www.npmjs.com/package/@microsoft/mgt-teamsfx-provider)

The [Microsoft Graph Toolkit (mgt)](https://aka.ms/mgt) library is a collection of authentication providers and UI components powered by Microsoft Graph. 

The `@microsoft/mgt-teamsfx-provider` package exposes the `TeamsFxProvider` class which uses [TeamsFx](https://www.npmjs.com/package/@microsoft/teamsfx) to sign in users and acquire tokens to use with Microsoft Graph.

To learn more about authentication providers, see [Providers](./providers.md).

## Usage

1. Install the packages

    ```bash
    npm install @microsoft/mgt-element @microsoft/mgt-teamsfx-provider @microsoft/teamsfx
    ```

1. Initialize the provider and login to get the required access token

    - Initialize the provider use `TeamsUserCredential` inside your component.

        ```ts
            // Import the providers and credential at the top of the page
            import {Providers} from '@microsoft/mgt-element';
            import {TeamsFxProvider} from '@microsoft/mgt-teamsfx-provider';
            import {TeamsUserCredential, TeamsUserCredentialAuthConfig} from "@microsoft/teamsfx";

            const authConfig: TeamsUserCredentialAuthConfig = {
                clientId: process.env.REACT_APP_CLIENT_ID,
                initiateLoginEndpoint: process.env.REACT_APP_START_LOGIN_PAGE_URL,
            };
            const scope = ["User.Read"];

            const credential = new TeamsUserCredential(authConfig);
            const provider = new TeamsFxProvider(credential, scope);
            Providers.globalProvider = provider;
        ```

    - Use the `credential.login(scopes)` method to get the required access token.

        ```ts
            // Put these code in a call-to-action callback function to avoid browser blocking automatically showing up pop-ups. 
            await credential.login(this.scope);
            Providers.globalProvider.setState(ProviderState.SignedIn);
        ```

1. Now you can add any component in your HTML page or in your `render()` method when using React and it will use the TeamsFx context to access Microsoft Graph.

    ```html
        <!-- Using HTML -->
        <mgt-person query="me" view="threeLines"></mgt-person>
    ```

    ```ts
        // Using React
        public render(): void {
            return (
                <div>
                    <Person personQuery="me" view={PersonViewType.threelines}></Person>
                </div>
            );
        }
    ```

For a sample that shows you how to initialize the TeamsFx provider, see the [Contacts Exporter sample](https://github.com/OfficeDev/TeamsFx-Samples/tree/dev/hello-world-tab-with-backend).

## See also
* [Microsoft Graph Toolkit docs](https://aka.ms/mgt-docs)
* [Microsoft Graph Toolkit repository](https://aka.ms/mgt)
* [Microsoft Graph Toolkit playground](https://mgt.dev)
* [TeamsFx docs](https://aka.ms/teamsfx-docs)
* [TeamsFx SDK document](https://learn.microsoft.com/microsoftteams/platform/toolkit/teamsfx-sdk)

---
_Source: https://npm.io/package/@mattbillfred/mgt-teamsfx-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
