Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a54a609
Update nodejs auto-signin sample
ceciliaavila Oct 20, 2025
d0df879
Update nodejs quickstart sample
ceciliaavila Oct 24, 2025
fb16f21
Update nodejs auto-signin sample
ceciliaavila Oct 27, 2025
b2515e8
Update nodejs obo-authorization sample
ceciliaavila Oct 29, 2025
b7ded13
Merge branch 'main' into southworks/update/nodejs-samples
ceciliaavila Oct 29, 2025
834a559
Update nodejs copilotstudio-client sample
ceciliaavila Oct 29, 2025
c6545fd
Update nodejs copilotstudio-skill sample
ceciliaavila Oct 29, 2025
86e1224
Update nodejs copilotstudio-webclient sample
ceciliaavila Oct 29, 2025
76ff026
Update nodejs copilotstudio-webchat-react sample
ceciliaavila Oct 29, 2025
37af122
Simplified Node auto-signin
Nov 5, 2025
c422eac
Merge branch 'main' of github.com:microsoft/Agents into southworks/up…
benbrown Nov 17, 2025
8218c8a
merge conflict
benbrown Nov 17, 2025
d589db0
expose public folder for skill manifest
benbrown Nov 17, 2025
60762e9
update cards sample to use express hosting
benbrown Nov 17, 2025
43f3719
update env.template files to new style of config
benbrown Nov 17, 2025
29615da
Merge branch 'main' into southworks/update/nodejs-samples
benbrown Nov 17, 2025
d3274ff
linter fixes
benbrown Nov 17, 2025
8b5f168
Merge branch 'southworks/update/nodejs-samples' of https://github.com…
benbrown Nov 17, 2025
b3b9b85
ignore browser.mjs
benbrown Nov 17, 2025
3b5912b
remove browser.mjs file
benbrown Nov 17, 2025
b2ae4ca
add package lock
benbrown Nov 17, 2025
da2acc0
Merge branch 'main' into southworks/update/nodejs-samples
benbrown Nov 18, 2025
ef61629
rename agent.ts to index.ts
benbrown Nov 18, 2025
4921bf7
Merge branch 'southworks/update/nodejs-samples' of https://github.com…
benbrown Nov 18, 2025
600bdad
Merge branch 'users/tracyboehrer/node-auto-signin' of https://github.…
benbrown Nov 18, 2025
2bf11f4
remove
benbrown Nov 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions samples/nodejs/auto-signin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ This Agent has been created using [Microsoft 365 Agents SDK](https://github.com/
This sample uses different routes, and some are configured to use one or more auth handlers:

```ts
this.onMessage('/logout', this._logout)
this.onMessage('/me', this._profileRequest, ['graph'])
this.onMessage('/prs', this._pullRequests, ['github'])
this.onMessage('/status', this._status, ['graph', 'github'])
this.onMessage('-me', this._profileRequest, ['graph'])
this.onMessage('-logout', this._logout)
```


Expand All @@ -33,8 +31,10 @@ The sample uses the bot OAuth capabilities in [Azure Bot Service](https://docs.b
1. Configuring the token connection in the Agent settings
> The instructions for this sample are for a SingleTenant Azure Bot using ClientSecrets. The token connection configuration will vary if a different type of Azure Bot was configured. For more information see [MSAL Authentication provider](https://learn.microsoft.com/microsoft-365/agents-sdk/azure-bot-authentication-for-javascript)

1. Open the `env.TEMAPLTE` file in the root of the sample project and rename it to `.env`
1. Update **clientId**, **tenantId** and **clientSecret**
1. Open the `env.TEMPLATE` file in the root of the sample project, rename it to `.env` and configure the following values:
1. Set the **connections__serviceConnection__settings__clientId** to the AppId of the bot identity.
2. Set the **connections__serviceConnection__settings__clientSecret** to the Secret that was created for your identity. *This is the `Secret Value` shown in the AppRegistration*.
3. Set the **connections__serviceConnection__settings__tenantId** to the Tenant Id where your application is registered.


1. Configure the UserAuthorization handlers
Expand All @@ -47,16 +47,12 @@ The sample uses the bot OAuth capabilities in [Azure Bot Service](https://docs.b
storage: new MemoryStorage(),
authorization: {
graph: { text: 'Sign in with Microsoft Graph', title: 'Graph Sign In' },
github: { text: 'Sign in with GitHub', title: 'GitHub Sign In' },
}
})
```

you should have one item for `graph` and aonther for `github`

```env
graph_connectionName=
github_connectionName=
```


Expand Down Expand Up @@ -91,7 +87,7 @@ The sample uses the bot OAuth capabilities in [Azure Bot Service](https://docs.b
## Interacting with the Agent

- When the conversation starts, you will be greeted with a welcome message, and another message informing the token status.
- Sending `/me` will trigger the OAuth flow and display additional information about you.
- Sending `-me` will trigger the OAuth flow and display additional information about you.
- Note that if running this in Teams and SSO is setup, you shouldn't see any "sign in" prompts. This is true in this sample since we are only requesting a basic set of scopes that Teams doesn't require additional consent for.

## Further reading
Expand Down
15 changes: 9 additions & 6 deletions samples/nodejs/auto-signin/env.TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
tenantId=
clientId=
clientSecret=
# rename to .env
connections__serviceConnection__settings__clientId= # App ID of the App Registration used to log in.
connections__serviceConnection__settings__clientSecret= # Client secret of the App Registration used to log in.
connections__serviceConnection__settings__tenantId= # Tenant ID of the App Registration used to log in.

graph_connectionName=
github_connectionName=
connectionsMap__0__connection=serviceConnection
connectionsMap__0__serviceUrl=*

DEBUG=agents:*:error,agents:*:info,agents:*:warn
graph_connectionName= # the connection name configured in the Azure Bot for graph authentication.

DEBUG=agents:*:error,agents:*:info,agents:*:warn
44 changes: 0 additions & 44 deletions samples/nodejs/auto-signin/src/githubApiClient.ts

This file was deleted.

82 changes: 11 additions & 71 deletions samples/nodejs/auto-signin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,27 @@ import { startServer } from '@microsoft/agents-hosting-express'
import { AgentApplication, CardFactory, MemoryStorage, MessageFactory, TurnContext, TurnState } from '@microsoft/agents-hosting'
import { Template } from 'adaptivecards-templating'
import { getUserInfo } from './userGraphClient.js'
import { getCurrentProfile, getPullRequests } from './githubApiClient.js'
import { ActivityTypes } from '@microsoft/agents-activity'

class AutoSignInDemo extends AgentApplication<TurnState> {
constructor () {
super({
storage: new MemoryStorage(),
authorization: {
graph: { text: 'Sign in with Microsoft Graph', title: 'Graph Sign In' },
github: { text: 'Sign in with GitHub', title: 'GitHub Sign In' },
}
})
this.onConversationUpdate('membersAdded', this._status)
this.authorization.onSignInSuccess(this._singinSuccess)
// this.authorization.onSignInFailure(this._singinFailure)
this.onMessage('/logout', this._logout)
this.onMessage('/me', this._profileRequest, ['graph'])
this.onMessage('/prs', this._pullRequests, ['github'])
this.onMessage('/status', this._status, ['graph', 'github'])
this.onActivity('invoke', this._invoke)
this.onActivity('message', this._message)
}

private _status = async (context: TurnContext, state: TurnState): Promise<void> => {
await context.sendActivity(MessageFactory.text('Welcome to the App Routes with auth demo!'))
const tokGraph = await this.authorization.getToken(context, 'graph')
const tokGH = await this.authorization.getToken(context, 'github')
const statusGraph = tokGraph.token !== undefined
const statusGH = tokGH.token !== undefined
await context.sendActivity(MessageFactory.text(`Token status: Graph:${statusGraph} GH:${statusGH}`))
this.authorization.onSignInFailure(this._singinFailure)
this.onMessage('-me', this._profileRequest, ['graph'])
this.onMessage('-logout', this._logout)
this.onActivity(ActivityTypes.Message, this._message)
}

private _logout = async (context: TurnContext, state: TurnState): Promise<void> => {
await this.authorization.signOut(context, state)
await context.sendActivity(MessageFactory.text('user logged out'))
}

private _invoke = async (context: TurnContext, state: TurnState): Promise<void> => {
await context.sendActivity(MessageFactory.text('Invoke received.'))
}

private _singinSuccess = async (context: TurnContext, state: TurnState, authId?: string): Promise<void> => {
await context.sendActivity(MessageFactory.text(`User signed in successfully in ${authId}`))
}

private _singinFailure = async (context: TurnContext, state: TurnState, authId?: string, err?: string): Promise<void> => {
await context.sendActivity(MessageFactory.text(`Signing Failure in auth handler: ${authId} with error: ${err}`))
}
Expand All @@ -59,49 +36,12 @@ class AutoSignInDemo extends AgentApplication<TurnState> {

private _profileRequest = async (context: TurnContext, state: TurnState): Promise<void> => {
const userTokenResponse = await this.authorization.getToken(context, 'graph')
if (userTokenResponse && userTokenResponse?.token) {
const userTemplate = (await import('./userProfileCard.json', { with: { type: 'json' } })).default
const template = new Template(userTemplate)
const userInfo = await getUserInfo(userTokenResponse?.token!)
const card = template.expand(userInfo)
const activity = MessageFactory.attachment(CardFactory.adaptiveCard(card))
await context.sendActivity(activity)
} else {
await context.sendActivity(MessageFactory.text(' token not available. Enter "/login" to sign in.'))
}
}

private _pullRequests = async (context: TurnContext, state: TurnState): Promise<void> => {
const userTokenResponse = await this.authorization.getToken(context, 'github')
if (userTokenResponse && userTokenResponse.token) {
const ghProf = await getCurrentProfile(userTokenResponse.token)
// console.log('GitHub profile', ghProf)

const userTemplate = (await import('./userProfileCard.json', { with: { type: 'json' } })).default
const template = new Template(userTemplate)
const card = template.expand(ghProf)
const activity = MessageFactory.attachment(CardFactory.adaptiveCard(card))
await context.sendActivity(activity)

const prs = await getPullRequests('microsoft', 'agents', userTokenResponse.token)
for (const pr of prs) {
const prCard = (await import('./pullRequestCard.json', { with: { type: 'json' } })).default
const template = new Template(prCard)
const toExpand = {
$root: {
title: pr.title,
url: pr.url,
id: pr.id,
}
}
const card = template.expand(toExpand)
await context.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(card)))
}
} else {
const tokenResponse = await this.authorization.beginOrContinueFlow(context, state, 'github')
console.warn(`GitHub token: ${JSON.stringify(tokenResponse)}`)
await context.sendActivity(MessageFactory.text('GitHub token length.' + tokenResponse?.token?.length))
}
const userTemplate = (await import('./userProfileCard.json', { with: { type: 'json' } })).default
const template = new Template(userTemplate)
const userInfo = await getUserInfo(userTokenResponse?.token!)
const card = template.expand(userInfo)
const activity = MessageFactory.attachment(CardFactory.adaptiveCard(card))
await context.sendActivity(activity)
}
}

Expand Down
3 changes: 3 additions & 0 deletions samples/nodejs/auto-signin/src/userGraphClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { AuthenticationProvider, Client } from '@microsoft/microsoft-graph-client'
import { User } from '@microsoft/microsoft-graph-types'

Expand Down
2 changes: 1 addition & 1 deletion samples/nodejs/azure-ai-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc -b",
"prestart": "npm run build",
"test-tool": "agentsplayground",
"start": "node --env-file .env dist/agent.js"
"start": "node --env-file .env dist/index.js"
},
"devDependencies": {
"@microsoft/m365agentsplayground": "^0.2.16",
Expand Down
11 changes: 8 additions & 3 deletions samples/nodejs/cards/env.TEMPLATE
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# rename to .env
tenantId=
clientId=
clientSecret=
connections__serviceConnection__settings__clientId= # App ID of the App Registration used to log in.
connections__serviceConnection__settings__clientSecret= # Client secret of the App Registration used to log in
connections__serviceConnection__settings__tenantId= # Tenant ID of the App Registration used to log in

connectionsMap__0__connection=serviceConnection
connectionsMap__0__serviceUrl=*

DEBUG=agents:*:error
Loading
Loading