예제 #1
0
 public AzureManagementService(TokenService tokenService, IOptions <AzureAdOptions> adOptions, HttpClient httpClient, ServicePrincipalRepository repository)
 {
     _tokenService = tokenService;
     _adOptions    = adOptions.Value;
     _httpClient   = httpClient;
     _repository   = repository;
 }
    public async Task update_azureAD_Application()
    {
        var appUri = string.Format("https://{0}/{1}", tenantId, "unittestmsiot");
        var repo   = new ServicePrincipalRepository(activeDirectoryClient, logger);
        var app    = await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                             appUri,
                                                             "msiot123",
                                                             tenantId);

        Assert.Equal("unittestmsiot", app.App.DisplayName);

        var updateModel = new UpdateApplicationRequest
        {
            Homepage  = "https://localhostunitest",
            ReplyUrls = new List <string>
            {
                "https://localhostunitest"
            }
        };
        await repo.UpdateAzureADApplication(app.App.ObjectId,
                                            updateModel,
                                            tenantId);

        app = await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                      appUri,
                                                      "msiot123",
                                                      tenantId);

        Assert.Equal(updateModel.Homepage, app.App.Homepage);
        Assert.True(app.App.ReplyUrls.Contains("https://localhostunitest"));
    }
 public async Task create_azureAD_app_service_principal_Exception()
 {
     var appUri = string.Format("https://{0}/{1}", tenantId, "unittestmsiot");
     var repo   = new ServicePrincipalRepository(activeDirectoryClient, logger);
     await Assert.ThrowsAsync <DataServiceQueryException>(async() => await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                                                                             appUri,
                                                                                                             "msiot123",
                                                                                                             tenantId + "sddra"));
 }
    public async Task create_azureAD_app_service_principal()
    {
        var appUri = string.Format("https://{0}/{1}", tenantId, "unittestmsiot");
        var repo   = new ServicePrincipalRepository(activeDirectoryClient, logger);
        var app    = await repo.CreateAppAndServicePrincipal("unittestmsiot1",
                                                             appUri,
                                                             "msiot123",
                                                             tenantId);

        Assert.Equal("unittestmsiot1", app.App.DisplayName);
    }
예제 #5
0
 public ServicePrincipalController(
     TokenService tokenService,
     GraphService graphService,
     IOptions <AzureAdOptions> adOptions,
     IOptions <OpenIdConnectOptions> oidcOptions,
     AzureManagementService azureManagementService,
     ServicePrincipalRepository repository)
 {
     _tokenService           = tokenService;
     _graphService           = graphService;
     _adOptions              = adOptions.Value;
     _oidcOptions            = oidcOptions.Value;
     _azureManagementService = azureManagementService;
     _repository             = repository;
 }
    public async Task update_azureAD_Application_PasswordCreds()
    {
        var appUri = string.Format("https://{0}/{1}", tenantId, "unittestmsiot");
        var repo   = new ServicePrincipalRepository(activeDirectoryClient, logger);
        var app    = await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                             appUri,
                                                             "msiot123",
                                                             tenantId);

        Assert.Equal("unittestmsiot", app.App.DisplayName);

        var updateModel = new UpdateApplicationRequest
        {
            Homepage  = "https://localhostunitest",
            ReplyUrls = new List <string>
            {
                "https://localhostunitest"
            }
        };
        await repo.UpdateAzureADApplication(app.App.ObjectId,
                                            updateModel,
                                            tenantId);

        app = await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                      appUri,
                                                      "msiot123",
                                                      tenantId);

        Assert.Equal(updateModel.Homepage, app.App.Homepage);
        Assert.True(app.App.ReplyUrls.Contains("https://localhostunitest"));

        // now update the password credentials object
        UpdateApplicationPasswordCredentials updateAppPasswordCreds =
            new UpdateApplicationPasswordCredentials
        {
            StartDate = DateTime.UtcNow,
            EndDate   = DateTime.UtcNow.AddYears(1),
            Value     = CreateRandomClientSecretKey(),
            KeyId     = Guid.NewGuid()
        };
        var passwordList = new List <UpdateApplicationPasswordCredentials>();

        passwordList.Add(updateAppPasswordCreds);

        var updateAppPasswordReq = new UpdateApplicationPasswordCredsRequest
        {
            UpdateApplicationPasswordCreds = passwordList
        };

        await repo.UpdateAzureADApplicationPasswordCredentials(app.App.ObjectId,
                                                               updateAppPasswordReq,
                                                               tenantId);

        app = await repo.CreateAppAndServicePrincipal("unittestmsiot",
                                                      appUri,
                                                      "msiot123",
                                                      tenantId);


        Assert.Equal(updateAppPasswordCreds.StartDate,
                     app.App.PasswordCredentials[0]
                     .StartDate);
        Assert.Equal(updateAppPasswordCreds.EndDate,
                     app.App.PasswordCredentials[0]
                     .EndDate);
    }
예제 #7
0
 public GraphService(TokenService tokenService, ServicePrincipalRepository repository)
 {
     _tokenService = tokenService;
     _repository   = repository;
 }