Skip to content

Revoke-MgUserSign NullReferenceException #1241

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

Closed
commakoerschgen opened this issue May 3, 2022 · 1 comment · Fixed by #1324
Closed

Revoke-MgUserSign NullReferenceException #1241

commakoerschgen opened this issue May 3, 2022 · 1 comment · Fixed by #1324

Comments

@commakoerschgen
Copy link

The cmdlet Revoke-MgUserSign internally suffers a NullReferenceException. The actual revocation is performed successfully and the exception occurs during response parsing.

Sample session:

PS C:\> Revoke-MgUserSign -UserId 0b2de3b6-ee9b-4c88-a846-bf26b146d42a
Revoke-MgUserSign_Revoke1: Object reference not set to an instance of an object.

PS C:\> Revoke-MgUserSign -UserId 0b2de3b6-ee9b-4c88-a846-bf26b146d42a -Debug
DEBUG: [CmdletBeginProcessing]: - Revoke-MgUserSign begin processing with parameterSet 'Revoke1'.
DEBUG: [Authentication]: - AuthType: 'Delegated', AuthProviderType: 'InteractiveAuthenticationProvider', ContextScope: 'CurrentUser', AppName: 'Microsoft Graph PowerShell'.
DEBUG: [Authentication]: - Scopes: [AuditLog.Read.All, Directory.Read.All, Domain.Read.All, openid, Policy.Read.All, profile, User.Read, email, User.ReadWrite.All].

Confirm
Are you sure you want to perform this action?
Performing the operation "Revoke-MgUserSign_Revoke1" on target "Call remote 'UsersRevokeSignInSessions1' operation".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): yes
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.com/v1.0/users/0b2de3b6-ee9b-4c88-a846-bf26b146d42a/microsoft.graph.revokeSignInSessions

Headers:
SdkVersion                    : graph-powershell/1.9.5,Graph-dotnet-1.25.1
FeatureFlag                   : 00000047
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.19044; en-US),PowerShell/7.2.2,Revoke-MgUserSign_Revoke1
Accept-Encoding               : gzip

Body:



DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Transfer-Encoding             : chunked
Location                      : https://graph.microsoft.com/
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : c83d8f73-7201-4ba6-867f-b2015462d662
client-request-id             : c83d8f73-7201-4ba6-867f-b2015462d662
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"AM2PEPF0000BE5B"}}
x-ms-resource-unit            : 1
OData-Version                 : 4.0
Date                          : Tue, 03 May 2022 11:35:43 GMT

Body:
{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Edm.Boolean",
  "value": true
}


DEBUG: [CmdletException]: Received exception with message 'NullReferenceException - Object reference not set to an instance of an object. :    at Microsoft.Graph.PowerShell.Cmdlets.RevokeMgUserSign_Revoke1.onOk(HttpResponseMessage responseMessage, Task`1 response)
   at Microsoft.Graph.PowerShell.UsersActions.UsersRevokeSignInSessions1_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.UsersActions.UsersRevokeSignInSessions1_Call(HttpRequestMessage request, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.UsersActions.UsersRevokeSignInSessions1(String userId, Func`3 onOk, Func`3 onDefault, IEventListener eventListener, ISendAsync sender)
   at Microsoft.Graph.PowerShell.Cmdlets.RevokeMgUserSign_Revoke1.ProcessRecordAsync()'
Revoke-MgUserSign_Revoke1: Object reference not set to an instance of an object.
DEBUG: [CmdletEndProcessing]: - Revoke-MgUserSign end processing.

This happens for both v1.0 and beta. SDK version 1.9.5, Powershell version 7.2.2

On a side note, the last part of the endpoint is microsoft.graph.revokeSignInSessions while the documentation says that it should just be revokeSignInSessions. That does not seem to be the problem, however.

@ghost ghost added the ToTriage label May 3, 2022
@peombwa
Copy link
Member

peombwa commented May 25, 2022

Sorry about this. The error is due to a mismatch of the response schema in the OpenAPI file that the SDK is generated from. See microsoftgraph/microsoft-graph-devx-api#726. As a workaround, I would recommend you can use Invoke-MgGraphRequest to revoke the signInSession of a user:

Invoke-MgGraphRequest -Uri "v1.0/users/USER_ID/microsoft.graph.revokeSignInSessions" -Method POST

We will provide a fix for this in the upcoming releases as part of #1265.

As for microsoft.graph.revokeSignInSessions vs revokeSignInSessions, this is by design. microsoft.graph is just the namespace of the action (revokeSignInSessions). See https://docs.microsoft.com/en-us/graph/use-the-api#odata-namespace.

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

Successfully merging a pull request may close this issue.

2 participants