How call to register printer with using provider is not calling popup dialog for Azure Login?

Copper Contributor

I have a client app where I can get berier token and pass it to service to Register printer.

But how to register printer without using delegating provider?

        private static IAuthenticationProvider GetDelegatedAuthProvider()
        {
            IPublicClientApplication app = PublicClientApplicationBuilder
                .Create(Config.ClientId)
                .WithTenantId(Config.Tenant)
                .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
                .WithDesktopFeatures()
                .Build();

            return new InteractiveAuthenticationProvider(app);
        }

if I use application provider then printer registration fails:

Microsoft.Graph.ServiceException: Code: 403
Message: The token does not have one or more required security scopes.

What should I do prevent using delegating provider for operations requiring delegation permissions in  the service?

2 Replies

@ktchoumak - to register a printer we need it to be done explicitly by a printer admin action - thats why there you need the delegated token. Please note, if you are registering multiple printers at the same time and session length exceeds the expiry time of the token (typically one hour), then you can refresh the token without requiring the user to login.

 

If there is a strong scenario where you absolutely need application token, then I recommend filing a feature request at https://aka.ms/UPIdeas. Please explain your scenario in detail.

 

Thanks,
Saurabh

Thanks for answer - I found solution: use custom provider:
public class myProvider : Microsoft.Graph.IAuthenticationProvider
{
string Token { get; set; }

public myProvider (string bearerToken)
{
Token = bearerToken;
}
public Task AuthenticateRequestAsync(HttpRequestMessage request)
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Token);
return Task.FromResult(false);
}
}