Esempio n. 1
0
 public HttpManager(
     IHttpClientFactory httpClientFactory,
     MsalClientConfiguration clientConfiguration)
 {
     _httpClientFactory       = httpClientFactory;
     _msalClientConfiguration = clientConfiguration;
 }
        public virtual IActionResult CreatePca([FromBody] MsalClientConfiguration body)
        {
            var    pca   = new PublicClientApplication(body.DefaultClientId, body.DefaultAuthority);
            string pcaId = Guid.NewGuid().ToString("N");

            _pcaMap.TryAdd(pcaId, pca);

            return(new ObjectResult(
                       new CreatePublicClientResult
            {
                PcaId = pcaId
            }));
            ////TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            //// return StatusCode(200, default(CreatePublicClientResult));

            ////TODO: Uncomment the next line to return response 405 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            //// return StatusCode(405);

            //string exampleJson = null;
            //exampleJson = "{\n  \"pcaId\" : \"pcaId\"\n}";

            //var example = exampleJson != null
            //? JsonConvert.DeserializeObject<CreatePublicClientResult>(exampleJson)
            //: default(CreatePublicClientResult);
            ////TODO: Change the data returned
            //return new ObjectResult(example);
        }
Esempio n. 3
0
        /// <summary>
        ///     Create a new public client application
        /// </summary>
        /// <param name="body">MsalClientConfiguration object to configure your PCA with</param>
        /// <returns>CreatePublicClientResult</returns>
        public CreatePublicClientResult CreatePca(MsalClientConfiguration body)
        {
            // verify the required parameter 'body' is set
            if (body == null)
            {
                throw new ApiException(400, "Missing required parameter 'body' when calling CreatePca");
            }

            string path = "/pca";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <string, string>();
            var    headerParams = new Dictionary <string, string>();
            var    formParams   = new Dictionary <string, string>();
            var    fileParams   = new Dictionary <string, FileParameter>();
            string postBody     = null;

            postBody = ApiClient.Serialize(body); // http body (model) parameter

            // authentication setting, if any
            var authSettings = new string[]
            {
                "msal_auth"
            };

            // make the HTTP request
            var response = (IRestResponse)ApiClient.CallApi(
                path,
                Method.POST,
                queryParams,
                postBody,
                headerParams,
                formParams,
                fileParams,
                authSettings);

            if ((int)response.StatusCode >= 400)
            {
                throw new ApiException(
                          (int)response.StatusCode,
                          "Error calling CreatePca: " + response.Content,
                          response.Content);
            }
            else if ((int)response.StatusCode == 0)
            {
                throw new ApiException(
                          (int)response.StatusCode,
                          "Error calling CreatePca: " + response.ErrorMessage,
                          response.ErrorMessage);
            }

            return((CreatePublicClientResult)ApiClient.Deserialize(
                       response.Content,
                       typeof(CreatePublicClientResult),
                       response.Headers));
        }
Esempio n. 4
0
 public NetFrameworkLogger(
     ISystemUtils systemUtils,
     Guid correlationId,
     MsalClientConfiguration msalClientConfiguration,
     ITimeService timeService = null)
 {
     _systemUtils             = systemUtils;
     CorrelationId            = correlationId;
     _msalClientConfiguration = msalClientConfiguration ??
                                throw new ArgumentNullException(nameof(msalClientConfiguration));
     _timeService = timeService ?? new TimeService();
 }
        public PublicClientApplicationProxy(
            string defaultClientId,
            string defaultAuthority,
            string endpointUrl = "https://localhost:44346/v2")
        {
            _publicClientApi = new PublicClientApi(new ApiClient(endpointUrl));
            var config = new MsalClientConfiguration
            {
                DefaultAuthority = defaultAuthority,
                DefaultClientId  = defaultClientId
            };

            var createResult = _publicClientApi.CreatePca(config);

            _publicClientApiId = createResult.PcaId;
        }
Esempio n. 6
0
        private async Task <string> AuthenticationCallbackAsync(
            string authority,
            string resource,
            string scope)
        {
            var msalConfiguration = new MsalClientConfiguration();
            var pca = new PublicClientApplication(msalConfiguration);
            //var authContext = new AuthenticationContext(authority, keyVaultTokenCache);

            var authParameters = new AuthenticationParameters
            {
                Authority = authority,
                ClientId  = _config.ClientId,
            };

            authParameters.AddScopes(ScopeUtils.Split(scope));
            authParameters.AddScope("https://vault.azure.net/.default");

            switch (_config.AuthType)
            {
            case KeyVaultAuthenticationType.ClientCertificate:
                var cert = CertificateHelper.FindCertificateByThumbprint(_config.CertThumbprint);
                authParameters.Certificate       = cert;
                authParameters.AuthorizationType = AuthorizationType.Certificate;

                // authContext.AcquireTokenAsync(resource, _assertionCert));
                break;

            case KeyVaultAuthenticationType.UserCredential:
                authParameters.AuthorizationType = AuthorizationType.WindowsIntegratedAuth;
                //authResult = await authContext.AcquireTokenAsync(resource, _config.ClientId, new UserCredential());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var authResult = await pca.AcquireTokenSilentlyAsync(authParameters, CancellationToken.None)
                             .ConfigureAwait(false);

            return(authResult?.AccessToken);
        }
Esempio n. 7
0
 /// <inheritdoc />
 public ILogger CreateLogger(
     Guid correlationId,
     MsalClientConfiguration msalClientConfiguration)
 {
     return(new NetFrameworkLogger(GetSystemUtils(), correlationId, msalClientConfiguration));
 }
Esempio n. 8
0
 public TelemetryManager(MsalClientConfiguration msalClientConfiguration)
 {
     _msalClientConfiguration = msalClientConfiguration;
 }
Esempio n. 9
0
 /// <inheritdoc />
 public HttpClient GetHttpClient(MsalClientConfiguration clientConfiguration)
 {
     return(_httpClient);
 }