Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Commerce forum / Accessing RetailServer...
Commerce forum

Accessing RetailServer externally with C1 authentication

Posted on by Microsoft Employee
I am trying to create an external application utilizing some of the RetailServer functionalities. C1 authorization is mandatory in my scenario. What is worth noting is that no customers or users will have access to this application it will be used as a form of automation only.

What I've done so far was:

1) Adding an application in Azure Active Directory.

2) Adding Identity Provider with clientId and secret from point 1) to D365.

3) Adding application in D365 in Azure Active Directory applications form with user that has full system access.

4) Creating a test method for fetching an existing cart from RetailServer.

Code:

AuthenticationContext authenticationContext = new AuthenticationContext(tenantAuthority, false);
AuthenticationResult authResult = null;
authResult = await authenticationContext.AcquireTokenAsync(retailserverAddress, new ClientCredential(clientID, clientSecret));
ClientCredentialsToken clientCredentialsToken = new ClientCredentialsToken(authResult.AccessToken);
Microsoft.Dynamics.Commerce.RetailProxy.RetailServerContext retailServerContext = Microsoft.Dynamics.Commerce.RetailProxy.RetailServerContext.Create(new Uri(retailserverAddress + "/Commerce"), OUN, clientCredentialsToken);
Microsoft.Dynamics.Commerce.RetailProxy.ManagerFactory managerFactory;
managerFactory = Microsoft.Dynamics.Commerce.RetailProxy.ManagerFactory.Create(retailServerContext);
Microsoft.Dynamics.Commerce.RetailProxy.ICartManager cartManagerTest = managerFactory.GetManager<Microsoft.Dynamics.Commerce.RetailProxy.ICartManager>();
Microsoft.Dynamics.Commerce.RetailProxy.Cart cartFromProxy = await cartManagerTest.Read(cartWithLine.Id);

What is important is that I do not want to extend or modify CRT/RS/D365 code. Is there any way to achive this?

Right now all my calls seem to be made as anonymous and therefore fail to be executed even when Azure Active Directory application user has full access.

Error:

An exception of type: 'Microsoft.Dynamics.Commerce.Runtime.UserAuthorizationException' occurred while executing Microsoft.Dynamics.Commerce.Runtime.Services.Messages.CheckAccessServiceRequest request by Microsoft.Dynamics.Commerce.Runtime.Services.UserAuthenticationService. Error resource id: 'Microsoft_Dynamics_Commerce_Runtime_AuthorizationFailed', Exception: Microsoft.Dynamics.Commerce.Runtime.UserAuthorizationException: Assigned role is not allowed to perform this operation.
   at Microsoft.Dynamics.Commerce.Runtime.Services.CommerceAuthorization.CheckAccess(ICommercePrincipal principal, RetailOperation operationId, RequestContext context, String[] allowedRoles, Boolean deviceTokenRequired, Boolean nonDrawerOperationCheckRequired)
   at Microsoft.Dynamics.Commerce.Runtime.Services.UserAuthenticationService.CheckAccess(CheckAccessServiceRequest request)
   at Microsoft.Dynamics.Commerce.Runtime.Services.UserAuthenticationService.Execute(Request request)
   at Microsoft.Dynamics.Commerce.Runtime.CommerceRuntime.Execute[TResponse](Request request, RequestContext context, IRequestHandler handler, Boolean skipRequestTriggers).


I would greatly appreciate any help as I refuse to believe that this is impossible.

  • SergeyP Profile Picture
    SergeyP 2,928 on at
    RE: Accessing RetailServer externally with C1 authentication

    Retail Server supports Service to Service authentication, it is described in

    Support for Service to Service authentication in Retail Server

    >… What is important is that I do not want to extend or modify CRT/RS/D365 code. Is there any way to achive this? ...

    Retail Server exposes many but not all operations for Service to Service authentication, if the ones you need are not available for that type of authentication you should create an extension and use proper CommerceAuthorization attribute in your controller's method, there is no any other way.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans