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

Move to Azure Identity #1201

Merged
merged 26 commits into from
Apr 18, 2022
Merged

Move to Azure Identity #1201

merged 26 commits into from
Apr 18, 2022

Conversation

peombwa
Copy link
Member

@peombwa peombwa commented Apr 12, 2022

This PR closes #1144 by:

  • Replacing deprecated auth providers with Azure Identity's token credentials.
  • Updating both unit and Pester tests.

The following improvements have been made to the Authentication module as part of this transition:

  • Drops -AccessToken from Invoke-MgGraphRequest. The goal is to have one authentication/authorization point, Connect-MgGraph.
  • Drops -ForceRefresh from Connect-MgGraph. -ForeceRefresh is not exposed by Azure Identity as the library will fetch new tokens automatically when new scopes are added.
  • Adds a simplified In-Memory token cache for process context scope.
  • Updates dependencies.

@peombwa peombwa marked this pull request as ready for review April 13, 2022 16:07
@ddyett
Copy link
Contributor

ddyett commented Apr 13, 2022

do you recall why we added the accesstoken on invoke-mggraphrequest to begin with?

{
InteractiveAuthenticationProvider,
DeviceCodeProvider,
DeviceCodeProviderFallBack,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was this one covering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeviceCodeProviderFallBack was used to detect when to fall back to DeviceCode when MSAL can't open browser in environments such as Linux servers. I've changed the implementation in https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/enhancements/MSIdentity/src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs#L157-L162 to catch the right MSAL exception and retry with device code.

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
<PackageReference Include="Azure.Core" Version="1.22.0" />
<PackageReference Include="Azure.Identity" Version="1.5.0" />
<PackageReference Include="Microsoft.Graph.Core" Version="2.0.8" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the time this goes out wouldn't kiota likely be the release? Is the plan to convert this later and align with CLI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the plan. Swapping the current MS Graph .NET core for Kiota based core should be trivial. I have a work item to integrate dependabot for verion updates - #1002.

@ddyett
Copy link
Contributor

ddyett commented Apr 13, 2022

can you say more about why the token caches for mac/linux are no longer necessary?

public class InMemoryTokenCacheOptions : UnsafeTokenCacheOptions
{
private readonly ReaderWriterLockSlim _sessionLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
internal ReadOnlyMemory<byte> TokenCache { get; private set; }
Copy link
Contributor

@ddyett ddyett Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd that the options class is holding the reference to the cache and operating on the object. This looks more like cache manager than options class

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! It is a cache manager. It's Azure Identity that named the base class UnsafeTokenCacheOptions. I opted to use the options suffix to be in sync with Azure Identity naming.

@peombwa
Copy link
Member Author

peombwa commented Apr 13, 2022

do you recall why we added the accesstoken on invoke-mggraphrequest to begin with?

It was because we didn't expose -AccessToken on Connect-MgGraph at the time.

@peombwa
Copy link
Member Author

peombwa commented Apr 14, 2022

can you say more about why the token caches for mac/linux are no longer necessary?

We no longer need them because Azure.Identity securely caches tokens on Windows, MacOS, and Linux (when libsecret-1.so.0 is available). We will fall back to in-memory cache when Azure.Identity can't persist tokens to the underlying OS mechanism (MsalCachePersistenceException is thrown).

@peombwa
Copy link
Member Author

peombwa commented Apr 14, 2022

We should verify that successfully sign in and token caching is possible on the following platforms (I'll check them once verified):

  • Windows:
    • PS 5.1
    • PS 7
    • WSL2
    • WSLg
  • MacOS:
    • PS core session via terminal
    • Docker
  • Linux:
    • Cloud Shell
    • Ubuntu
    • Ubuntu Server

@georgend
Copy link
Contributor

georgend commented Apr 15, 2022

do you recall why we added the accesstoken on invoke-mggraphrequest to begin with?

We had added it for BYOT scenarios. For example authenticating against Managed Identity in a Virtual Machine, getting a token and (re)-using it with the SDK.

@peombwa peombwa merged commit 805b08a into features/2.0 Apr 18, 2022
@peombwa peombwa deleted the enhancements/MSIdentity branch April 19, 2022 15:09
@peombwa peombwa mentioned this pull request Apr 19, 2022
2 tasks
This pull request was closed.
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

Successfully merging this pull request may close these issues.

4 participants