Skip to Content
avatar image
Former Member

OdataStore.OpenAsync fails throwing 401-Unauthorized Error

Dear Experts,

Here we are creating an Native Windows application for Windows 10 tablet devices consuming odata services using Native Odata SDK. We have configured everything for SSO and the registration from client to SMP server is happening. But as you might be aware of we need to create odata store and use OpenAsync() to retrieve metadata. But executing this statement throws 401-Unauthorized error. Below is the code snippet :

public async Task<bool> register()

{

try

{

if (Globals.LogonCore == null)

Globals.LogonCore = await SAP.Logon.Core.LogonCore.InitWithApplicationIdAsync(ApplicationId);

if (Globals.LogonCore.State.IsRegistered)

{

await Globals.LogonCore.UnlockSecureStoreAsync("12345678");

}

else

{

var logonContext = new SAP.Logon.Core.LogonContext

{

RegistrationContext = new RegistrationContext

{

ApplicationId = ApplicationId,

ServerHost = ServerHost,

IsHttps = false,

ServerPort = 8080,

BackendUserName = ActiveDirectoryUsername,

BackendPassword = ActiveDirectoryPassword,

SecurityConfig = SecurityConfig,

}

};

Globals.LogonCore.LogonContext = logonContext;

await Globals.LogonCore.RegisterWithContextAsync(logonContext);

await Globals.LogonCore.PersistRegistrationAsync("12345678", logonContext);

var connectionId = Globals.LogonCore.ApplicationSettings.ApplicationConnectionId;

System.Diagnostics.Debug.WriteLine("Application Id : " + connectionId);

// ischeck = true;

}

string serviceUri = Globals.LogonCore.LogonContext.RegistrationContext.ConnectionData["ProxyApplicationEndpoint"].ToString();

if(!string.IsNullOrEmpty(serviceUri) && !string.IsNullOrWhiteSpace(serviceUri))

{

onlinestore = new ODataStore(serviceUri, EntityFormat.Json);

client = new HttpClient();

client.ShouldHandleXcsrfToken = true;

using (var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter())

{

var cookieCollection = filter.CookieManager.GetCookies(new Uri(serviceUri));

foreach (var cookie in cookieCollection)

{

client.DefaultRequestHeaders.TryAddWithoutValidation(cookie.Name, cookie.Value);

}

}

await onlinestore.OpenAsync(client);

}

return true;

}

catch (Exception ex)

{

System.Diagnostics.Debug.WriteLine("Exception : " + ex.Message);

return false;

}

}


Also here above we are passing username and password for OpenAsync(). We are trying to get the cookies and pass it as header. But we are not able to get the cookie "MySAPSSO2" which is been configured in the security profile. Any idea how to get this and any solution for the 401-Unauthorized is appreciable.

Thanks,

Vivek.M

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 20, 2017 at 04:36 PM

    Hi Vivek, I am also getting the same issue. Have you found the solution? If so, please share.

    Add comment
    10|10000 characters needed characters exceeded