Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a MSGraph Client with an already-existing accessToken #1481

Closed
tyteen4a03 opened this issue Oct 8, 2023 · 4 comments
Closed

Creating a MSGraph Client with an already-existing accessToken #1481

tyteen4a03 opened this issue Oct 8, 2023 · 4 comments

Comments

@tyteen4a03
Copy link

I am trying to access MSGraph based on an access token. All of the tutorials seem to gear towards also fetching the access token for me, which I don't need.

Are there any examples where I can just pass in an access token to get to a client?

@tyteen4a03
Copy link
Author

I ended up doing this:

export const createAccessTokenClient = (accessToken: string): Client => {
    const authProvider = new (class implements AuthenticationProvider {
        async getAccessToken() {
            return accessToken;
        }
    })();

    return Client.initWithMiddleware({
        debugLogging: true,
        authProvider: authProvider,
    });
};

@sebastienlevert
Copy link
Contributor

You did exactly the right thing! Providing your own authProvider is the right approach! I'll be closing it for now!

@tyteen4a03
Copy link
Author

You did exactly the right thing! Providing your own authProvider is the right approach! I'll be closing it for now!

Can this be included in the documentation?

@sebastienlevert
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants