镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.19 KB

CustomAuthenticationProvider.md

File metadata and controls

36 lines (26 loc) · 1.19 KB

Using Custom Authentication Provider

Using preferred choice of Authentication library for authenticating with Microsoft is possible.

Step by step procedure

Implement AuthenticationProvider

Create own implementation of Authentication provider which implements AuthenticationProvider interface.

// MyAuthenticationProvider.ts
import { AuthenticationProvider } from "@microsoft/microsoft-graph-client";

class MyAuthenticationProvider implements AuthenticationProvider {
	/**
	 * This method will get called before every request to the msgraph server
	 * This should return a Promise that resolves to an accessToken (in case of success) or rejects with error (in case of failure)
	 * Basically this method will contain the implementation for getting and refreshing accessTokens
	 */
	public async getAccessToken(): Promise<string> {}
}

Initialize Client

Pass instance of MyAuthenticationProvider while initializing.

import { MyAuthenticationProvider } from "./MyAuthenticationProvider";

let clientOptions: ClientOptions = {
	authProvider: new MyAuthenticationProvider(),
};
const client = Client.initWithMiddleware(clientOptions);