C# ADAL AcquireTokenAsync() without pop-up box

前端 未结 3 1609
不思量自难忘°
不思量自难忘° 2021-01-02 17:06

We are writing a WCF service which has to integrate with Dynamics CRM 2016 Online. I\'m trying to authenticate using ADAL, using method AcquireTokenAsync(). Pro

3条回答
  •  旧巷少年郎
    2021-01-02 17:27

    Okay, ended up finding a solution for this.

    Provided you have registered your application with Azure AD (as a Web App / Web API, not a Native Application), you will receive a client ID and a secret key for that application.

    The code to acquire the token without having a pop-up window is as follows:

    AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(
                            new Uri(resource+"/api/data/v8.1")).Result;
    
    AuthenticationContext ac = new AuthenticationContext(ap.Authority);
    
    AuthenticationResult r = await ac.AcquireTokenAsync(ap.Resource, new ClientCredential(clientId,clientSecret));
    

    resource is the base URL of your Dynamics CRM deployment.

    Authentication parameters are discovered at run time as suggested in this MSDN acticle.

提交回复
热议问题