TeamsFx class

Warning

This API is now deprecated.

Please use TeamsUserCredential in browser environment and OnBehalfOfUserCredential or AppCredential in NodeJS.

A class providing credential and configuration.

Constructors

TeamsFx(IdentityType, AuthenticationConfiguration | Record<string, string>)

Constructor of TeamsFx

Methods

getConfig(string)

Usually used by service plugins to retrieve specific config

getConfigs()

Get all configurations.

getCredential()

Credential instance according to identity type choice.

getIdentityType()

Identity type set by user.

getUserInfo(string[])

Get user information.

hasConfig(string)

Check the value of specific key.

login(string | string[], string[])

Popup login page to get user's access token with specific scopes.

Example

await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
setSsoToken(string)

Set SSO token when using user identity in NodeJS.

Constructor Details

TeamsFx(IdentityType, AuthenticationConfiguration | Record<string, string>)

Constructor of TeamsFx

new TeamsFx(identityType?: IdentityType, customConfig?: AuthenticationConfiguration | Record<string, string>)

Parameters

identityType
IdentityType

Choose user or app identity

customConfig

AuthenticationConfiguration | Record<string, string>

key/value pairs of customized configuration that overrides default ones.

Method Details

getConfig(string)

Usually used by service plugins to retrieve specific config

function getConfig(key: string): string

Parameters

key

string

configuration key.

Returns

string

value in configuration.

getConfigs()

Get all configurations.

function getConfigs(): Record<string, string>

Returns

Record<string, string>

key value mappings.

getCredential()

Credential instance according to identity type choice.

function getCredential(): TokenCredential

Returns

instance implements TokenCredential interface.

Remarks

If user identity is chose, will return TeamsUserCredential in browser environment and OnBehalfOfUserCredential in NodeJS. If app identity is chose, will return AppCredential.

getIdentityType()

Identity type set by user.

function getIdentityType(): IdentityType

Returns

identity type.

getUserInfo(string[])

Get user information.

function getUserInfo(resources?: string[]): Promise<UserInfo>

Parameters

resources

string[]

The optional list of resources for full trust Teams apps.

Returns

Promise<UserInfo>

UserInfo object.

hasConfig(string)

Check the value of specific key.

function hasConfig(key: string): boolean

Parameters

key

string

configuration key.

Returns

boolean

true if corresponding value is not empty string.

login(string | string[], string[])

Popup login page to get user's access token with specific scopes.

Example

await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
function login(scopes: string | string[], resources?: string[]): Promise<void>

Parameters

scopes

string | string[]

The list of scopes for which the token will have access, before that, we will request user to consent.

resources

string[]

The optional list of resources for full trust Teams apps.

Returns

Promise<void>

Remarks

Only works in Teams client APP. User will be redirected to the authorization page to login and consent.

setSsoToken(string)

Set SSO token when using user identity in NodeJS.

function setSsoToken(ssoToken: string): TeamsFx

Parameters

ssoToken

string

used for on behalf of user flow.

Returns

self instance.