Skip to content

Commit

Permalink
📝 Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
wictorwilen committed Jun 15, 2021
1 parent ba9ce0a commit 6fe36eb
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 17 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
lib
node_modules
**/*.spec.*
File renamed without changes.
1 change: 0 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run lint
- run: npm run test
- run: npm run build
env:
CI: true
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tsconfig.json
.travis.yml
tslint.json
.eslintrc.json
.eslintignore
59 changes: 54 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# teams-simpleauth

A node.js Microsoft Teams simpleauth implementation
A node.js Microsoft Teams simpleauth implementation that works with the [@microsoft/teamsfx](https://www.npmjs.com/package/@microsoft/teamsfx) client side component.

## Installation

Expand All @@ -15,12 +15,61 @@ Install with npm

### Prerequisites

### Installation
A Teams Tab project using [Express.js](http://expressjs.com/) as a server side implementation, for instance a project scaffolded with [Yo Teams](https://aka.ms/yoteams)

1. Install the `teams-simpleauth` package
2. Install the `"@microsoft/teamsfx` package
3.
### Installation and configuration

Start by installing the `teams-simpleauth` and `@microsoft/teamsfx` packages. The first one is used for the server side *exchange* of the token and the latter one is for the client side scripting.

``` bash
npm install teams-simpleauth @microsoft/teamsfx --save
```

Next, in your server side component add the following import. For *yo teams* based applications this is in the `src/server/server.ts` file.

``` Typescript
import { simpleAuthRouter } from "teams-simpleauth";
```

And then after the express application is create add a statement like this to add and configure the router.

`appId`, `appIdUri` and `appSecret` are retrieved from the AAD application that is used for the Teams SSO Tab. `scopes` is an array of delegated permission scopes you would like for the returned access token and finally `tenantId` is either the ID of the tenant or set to `common` for multi-tenant applications.

``` Typescript
express.use("/auth/token", simpleAuthRouter({
appId: process.env.TAB_APP_ID as string,
appIdUri: process.env.TAB_APP_URI as string,
appSecret: process.env.TAB_APP_SECRET as string,
scopes: ["Presence.Read"],
tenantId: "00000000-0000-0000-0000-000000000000"
}));
```

In the client side code (tab) you need to import the `teamsfx` package as follows, and you use the package as described in the [`teamsfx` documentation](https://www.npmjs.com/package/@microsoft/teamsfx).

``` Typescript
import * as teamsFx from "@microsoft/teamsfx";
```


Example of tab using the `teamsfx` component in a *yo teams* based tab:

``` TypeScript
teamsFx.loadConfiguration({
authentication: {
initiateLoginEndpoint: `https://${process.env.PUBLIC_HOSTNAME}/ile`,
clientId: process.env.TAB_APP_ID,
tenantId: "00000000-0000-0000-0000-000000000000",,
authorityHost: "https://login.microsoftonline.com",
applicationIdUri: process.env.TAB_APP_URI,
simpleAuthEndpoint: `https://${process.env.PUBLIC_HOSTNAME}`
}
});
const credential = new teamsFx.TeamsUserCredential();
const graphClient = teamsFx.createMicrosoftGraphClient(credential, ["Presence.Read"]);
const result = await graphClient.api("/me/presence").get();
setPresence(" is " + result.availability);
```

## License

Expand Down
17 changes: 7 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-simpleauth",
"version": "1.0.0-preview",
"version": "1.0.0-preview2",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -37,6 +37,7 @@
"eslint": "^7.28.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"typescript": "^4.3.2"
Expand Down
20 changes: 20 additions & 0 deletions src/ISimpleAuthRouterOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
// Copyright (c) Wictor Wilén. All rights reserved.
// Licensed under the MIT license.
/**
* Options for the Teams Simpleauth router
*/
export interface ISimpleAuthRouterOptions {
/**
* The application/client id
*/
appId: string;
/**
* The application/client id URI
*/
appIdUri: string;
/**
* The appclication/client secret required for the on-behalf-of OAuth flow
*/
appSecret: string;
/**
* Scopes requested
*/
scopes: string[];
/**
* Tenant id or "common" for multi-tenant applications
*/
tenantId: string | "common";
};
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// Copyright (c) Wictor Wilén. All rights reserved.
// Licensed under the MIT license.
export { ISimpleAuthRouterOptions } from "./ISimpleAuthRouterOptions";
export { simpleAuthRouter } from "./simpleAuthRouter";
15 changes: 15 additions & 0 deletions src/simpleAuthRouter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
// Copyright (c) Wictor Wilén. All rights reserved.
// Licensed under the MIT license.
import { Router } from "express";
import { Passport } from "passport";
import { BearerStrategy, IBearerStrategyOption, ITokenPayload, VerifyCallback } from "passport-azure-ad";
import { ConfidentialClientApplication } from "@azure/msal-node";
import { ISimpleAuthRouterOptions } from "./ISimpleAuthRouterOptions";

/**
* Creates the Teams Simpleauth router
* @param options options for the router
* @returns an Express router
* @example
* express.use("/auth/token", simpleAuthRouter({
* appId: process.env.TAB_APP_ID as string,
* appIdUri: process.env.TAB_APP_URI as string,
* appSecret: process.env.TAB_APP_SECRET as string,
* scopes: ["Presence.Read"],
* tenantId: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
* }));
*/
export const simpleAuthRouter = (options: ISimpleAuthRouterOptions): Router => {
const router = Router();

Expand Down

0 comments on commit 6fe36eb

Please sign in to comment.