Compartilhar via


OnBehalfOfUserCredential class

Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.

Example

const credential = new OnBehalfOfUserCredential(ssoToken);

Remarks

Can only be used in server side.

Constructors

OnBehalfOfUserCredential(string, AuthenticationConfiguration)

Constructor of OnBehalfOfUserCredential

OnBehalfOfUserCredential(string, OnBehalfOfCredentialAuthConfig)

Constructor of OnBehalfOfUserCredential

Methods

getToken(string | string[], GetTokenOptions)

Get access token from credential.

Example

await credential.getToken([]) // Get SSO token using empty string array
await credential.getToken("") // Get SSO token using empty string
await credential.getToken([".default"]) // Get Graph access token with default scope using string array
await credential.getToken(".default") // Get Graph access token with default scope using string
await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
await credential.getToken("User.Read") // Get Graph access token for single scope using string
await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
getUserInfo()

Get basic user info from SSO token.

Example

const currentUser = getUserInfo();

Constructor Details

OnBehalfOfUserCredential(string, AuthenticationConfiguration)

Constructor of OnBehalfOfUserCredential

new OnBehalfOfUserCredential(ssoToken: string, config: AuthenticationConfiguration)

Parameters

ssoToken

string

User token provided by Teams SSO feature.

config
AuthenticationConfiguration

The authentication configuration. Use environment variables if not provided.

Remarks

Only works in in server side.

OnBehalfOfUserCredential(string, OnBehalfOfCredentialAuthConfig)

Constructor of OnBehalfOfUserCredential

new OnBehalfOfUserCredential(ssoToken: string, config: OnBehalfOfCredentialAuthConfig)

Parameters

ssoToken

string

User token provided by Teams SSO feature.

config
OnBehalfOfCredentialAuthConfig

The authentication configuration.

Remarks

Only works in in server side.

Method Details

getToken(string | string[], GetTokenOptions)

Get access token from credential.

Example

await credential.getToken([]) // Get SSO token using empty string array
await credential.getToken("") // Get SSO token using empty string
await credential.getToken([".default"]) // Get Graph access token with default scope using string array
await credential.getToken(".default") // Get Graph access token with default scope using string
await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
await credential.getToken("User.Read") // Get Graph access token for single scope using string
await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<null | AccessToken>

Parameters

scopes

string | string[]

The list of scopes for which the token will have access.

options
GetTokenOptions

The options used to configure any requests this TokenCredential implementation might make.

Returns

Promise<null | AccessToken>

Access token with expected scopes.

Remarks

If scopes is empty string or array, it returns SSO token. If scopes is non-empty, it returns access token for target scope.

getUserInfo()

Get basic user info from SSO token.

Example

const currentUser = getUserInfo();
function getUserInfo(): UserInfo

Returns

Basic user info with user displayName, objectId and preferredUserName.