microsoft / Intune-Resource-Access

Sample code and scripts for interfacing with the Intune Resource Access APIs.
MIT License
55 stars 59 forks source link

Application Authentication instead of an user #86

Open pedrr opened 4 years ago

pedrr commented 4 years ago

Please add the functionality to authenticate with the application itself and not delegated permissions. This will enable authentication via certificate instead of username/password.

ThomasKur commented 2 years ago

This would be really usefull

darba commented 2 years ago

Check out the development branch. With the move to MSAL we now offer other options besides username/password. It will move to master soon.

ThomasKur commented 2 years ago

There is a much simpler thin. I will publish it in a few days. You can use the new Microsoft.Graph module which is much better and supports everything. I only continue to use the module here to encrypt the pfx password, so probably the module could just be reduced to create the correct object.

  $UserPfx = New-IntuneUserPfxCertificate -PathToPfxFile "$($env:ProgramData)\baseVISION-SMIME\temp\cert.pfx" -PfxPassword  $Password -ProviderName "Microsoft Software Key Storage Provider" -KeyName "SMIME" -IntendedPurpose SmimeSigning -UPN $Upn

      # creating hashtable as an object is not working
      $UserPfxBody = @{
          CreatedDateTime = $UserPfx.CreatedDateTime 
          EncryptedPfxBlob  = $UserPfx.EncryptedPfxBlob
          EncryptedPfxPassword = $UserPfx.EncryptedPfxPassword
          ExpirationDateTime = $UserPfx.ExpirationDateTime.DateTime
          IntendedPurpose = $UserPfx.IntendedPurpose
          KeyName = $UserPfx.KeyName
          LastModifiedDateTime = $UserPfx.LastModifiedDateTime.DateTime
          PaddingScheme = $UserPfx.PaddingScheme
          ProviderName = $UserPfx.ProviderName
          StartDateTime = $UserPfx.StartDateTime.DateTime
          Thumbprint = $UserPfx.Thumbprint
          UserPrincipalName = $UserPfx.UserPrincipalName
      }
      Write-Log -Message "Start uploading cert to Intune" -Type Debug
      New-MgDeviceManagementUserPfxCertificate -BodyParameter $UserPfxBody