microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
690 stars 165 forks source link

Update authentication with Graph SDK #2486

Open worldsdream opened 9 months ago

worldsdream commented 9 months ago

Is your feature request related to a problem? Please describe. We can’t set authentication methods with Graph SDK. We have to use entra admin center or https://learn.microsoft.com/en-us/graph/api/authentication-update?view=graph-rest-beta&tabs=http

Describe the solution you'd like A feature to get the option for setting the authentication methods with Microsoft Graph PowerShell SDK.

Describe alternatives you've considered We can use: https://learn.microsoft.com/en-us/graph/api/authentication-update?view=graph-rest-beta&tabs=http

ioamnesia commented 8 months ago

This is very easy to do using the all purpose Invoke-mgGraphRequest cmdlet. Just figure out what values you want to set and put them in the body hashtable. Leave out ones you don't want to modify.

invoke-mgGraphRequest -Uri 'https://graph.microsoft.com/beta/users/[UPN OR ID]/authentication/signInPreferences' -Method PATCH -Body @{systemPreferredMethodForSecondaryAuthentication = "push"; isSystemPreferredAuthenticationMethodEnabled= "false"; userPreferredMethodForSecondaryAuthentication= "push"}

timayabi2020 commented 8 months ago

Hi @worldsdream have you tried using Invoke-MgGraphRequest as per @ioamnesia's suggestion?

worldsdream commented 8 months ago

@timayabi2020 It works with Invoke-RestMethod.

But isn’t the graph sdk so we can interact with Graph using PowerShell?

timayabi2020 commented 8 months ago

@timayabi2020 It works with Invoke-RestMethod.

But isn’t the graph sdk so we can interact with Graph using PowerShell? Invoke-MgGraphRequest is a commandlet within the Microsoft Graph PowerShell SDK. See documentation here

worldsdream commented 8 months ago

I thought that we will get an option. For example with “Get-“.

timayabi2020 commented 3 days ago

@worldsdream please update to the latest SDK version and use Update-MgBetaUserAuthenticationSignInPreference. An example is available here https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.beta.identity.signins/update-mgbetauserauthenticationsigninpreference?view=graph-powershell-beta which you can try out.