OneSignal / onesignal-dotnet-api

Other
13 stars 12 forks source link

[Bug]: DeleteUser returns 401 This operation requires 'Authorization' in the HTTP header #49

Closed ihijazi closed 1 month ago

ihijazi commented 1 month ago

What happened?

I'm using the latest .NET SDK, version 2.0.2. The DeleteUser was working fine (and still), but recently it's giving an excpetion.

Notes:

  1. Identity Verification for email + external_id (recommended) is NOT enabled for the app.
  2. The delete user is still partially working. What I mean by that, is that I can I still can find the subscription, but the external_id is deleted from it

This problem just started to happen, nothing changed really from our end.

Can you please advise on what might be wrong here?

Steps to reproduce?

Code used:

     var appConfig = new Configuration();
        appConfig.BasePath = oneSignalApiUrl;
        appConfig.AccessToken = oneSignalAccessToken;

        var apiInstance = new DefaultApi(appConfig);

        try
        {
            apiInstance.DeleteUser(oneSignalAppId, "external_id", payloadData.Username);
            return true;
        }

### What did you expect to happen?

No exception
Subscription to be fully deleted, not just the external_id within it.

### Relevant log output

```Shell
Error calling DeleteUser: 
{
    "errors": [
        {
            "code": "auth-1",
            "title": "This operation requires 'Authorization' in the HTTP header"
        }
    ]
}
   at OneSignalApi.Api.DefaultApi.DeleteUserWithHttpInfo(String appId, String aliasLabel, String aliasId, Int32 operationIndex)
   at OneSignalApi.Api.DefaultApi.DeleteUser(String appId, String aliasLabel, String aliasId, Int32 operationIndex)

Code of Conduct

ihijazi commented 1 month ago

Fixed it by adding headers manually for authorization.

Weird thing it used to work fine with just setting AccessToken.

Also documentation doesn't mention this.

Here is what I did:

var appConfig = new Configuration();
appConfig.BasePath = oneSignalApiUrl;
//appConfig.AccessToken = oneSignalAccessToken;
appConfig.DefaultHeaders.Add("Authorization", "Basic " + oneSignalAccessToken);

Closing this.