r/PowerShell • • Jan 26 '22

Solved Best way to use Microsoft Graph API without showing secret key?

I've been following along The Lazy Administrator's Guide. I'm fairly new to all this, and I am stuck with the method to connect to Graph. I have the IDs and Secret Key, but not sure how I can add it to a script without revealing what those keys are. Based on the guide, I think the best one to use is the Client Credentials, but again not sure how to "encrypt the client secret, store it in Azure Key Vault".

For context, I am learning how to use Graph API so I can send emails from a script I made in Powershell.

9 Upvotes

31 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Jan 27 '22

Wait, I think I figured it out. Tried to send a test mail, but got a 401 unauthorized. Hmm..

EDIT: I GOT IT.

1

u/theSysadminChannel Jan 27 '22

Nice. Please share the code so it can help others.

1

u/[deleted] Jan 28 '22

It was the one you sent with the Invoke-GraphRequest. I was following along the guide I posted and the invoke part of it was different. I changed it to the invoke-graphrequest and it worked. As you said, it was due to the token being embedded to the session. Thanks again!