コード例 #1
0
ファイル: GraphClient.cs プロジェクト: tmrconsultweb/TMRC-CSP
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphClient"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        /// <param name="client">Provides the ability to interact with the Microsoft Graph.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// or
        /// <paramref name="client"/> is null.
        /// </exception>
        public GraphClient(IExplorerProvider provider, IGraphServiceClient client)
        {
            provider.AssertNotNull(nameof(provider));
            client.AssertNotNull(nameof(client));

            this.provider = provider;
            this.client   = client;
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceManager"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        /// <param name="token">A valid JSON Web Token (JWT).</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="token"/> is empty or null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public ResourceManager(IExplorerProvider provider, string token)
        {
            provider.AssertNotNull(nameof(provider));
            token.AssertNotEmpty(nameof(token));

            client        = new ResourceManagementClient(new TokenCredentials(token));
            this.provider = provider;
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticationProvider"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        /// <param name="customerId">Identifier for customer whose resources are being accessed.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public AuthenticationProvider(IExplorerProvider provider, string customerId)
        {
            provider.AssertNotNull(nameof(provider));
            customerId.AssertNotEmpty(nameof(customerId));

            this.customerId = customerId;
            this.provider   = provider;
        }
コード例 #4
0
        public ActionResult UsersAccount()
        {
            IExplorerProvider provider = null;

            ViewModel.Users.Users users = new ViewModel.Users.Users(provider);
            //IEnumerable<Microsoft.Store.PartnerCenter.Models.Customers.Customer> obj =
            users.Get("c1bf1bc9-7e27-4c17-9012-3164bd408264");
            return(View("Admin/Users"));
        }
コード例 #5
0
ファイル: GraphClient.cs プロジェクト: tmrconsultweb/TMRC-CSP
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphClient"/> class.
        /// </summary>
        /// <param name="provider">Provides access to core services.</param>
        /// <param name="customerId">Identifier for customer whose resources are being accessed.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public GraphClient(IExplorerProvider provider, string customerId)
        {
            provider.AssertNotNull(nameof(provider));
            customerId.AssertNotEmpty(nameof(customerId));

            this.customerId = customerId;
            this.provider   = provider;

            client = new GraphServiceClient(new AuthenticationProvider(this.provider, customerId), httpProvider);
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DistributedTokenCache"/> class.
        /// </summary>
        /// <param name="provider">Provides access to the core explorer providers.</param>
        /// <param name="resource">The resource being accessed.</param>
        /// <param name="key">The unique identifier for the cache entry.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="resource"/> is empty or null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="provider"/> is null.
        /// </exception>
        public DistributedTokenCache(IExplorerProvider provider, string resource, string key = null)
        {
            provider.AssertNotNull(nameof(provider));
            resource.AssertNotEmpty(nameof(resource));

            this.provider = provider;
            keyValue      = key;
            this.resource = resource;

            AfterAccess  = AfterAccessNotification;
            BeforeAccess = BeforeAccessNotification;
        }
コード例 #7
0
        /// <summary>
        /// Configures authentication for the application.
        /// </summary>
        /// <param name="app">The application to be configured.</param>
        public void ConfigureAuth(IAppBuilder app)
        {
            IExplorerProvider provider = UnityConfig.Container.Resolve <IExplorerProvider>();

            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
            {
                ClientId  = provider.Configuration.ApplicationId,
                Authority = $"{provider.Configuration.ActiveDirectoryEndpoint}/common",

                Notifications = new OpenIdConnectAuthenticationNotifications
                {
                    AuthenticationFailed = (context) =>
                    {
                        // Track the exceptions using the telemetry provider.
                        provider.Telemetry.TrackException(context.Exception);

                        // Pass in the context back to the app
                        context.OwinContext.Response.Redirect($"/Home/Error?message={context.Exception.Message}");

                        // Suppress the exception
                        context.HandleResponse();

                        return(Task.FromResult(0));
                    },
                    AuthorizationCodeReceived = async(context) =>
                    {
                        string userTenantId         = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
                        string signedInUserObjectId = context.AuthenticationTicket.Identity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

                        IGraphClient client = new GraphClient(provider, userTenantId);

                        List <RoleModel> roles = await client.GetDirectoryRolesAsync(signedInUserObjectId).ConfigureAwait(false);

                        foreach (RoleModel role in roles)
                        {
                            context.AuthenticationTicket.Identity.AddClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Role, role.DisplayName));
                        }

                        bool isPartnerUser = userTenantId.Equals(
                            provider.Configuration.ApplicationTenantId, StringComparison.CurrentCultureIgnoreCase);

                        string customerId = string.Empty;

                        if (!isPartnerUser)
                        {
                            try
                            {
                                Customer c = await provider.PartnerOperations.GetCustomerAsync(userTenantId).ConfigureAwait(false);
                                customerId = c.Id;
                            }
                            catch (PartnerException ex)
                            {
                                if (ex.ErrorCategory != PartnerErrorCategory.NotFound)
                                {
                                    throw;
                                }
                            }
                        }

                        if (isPartnerUser || !string.IsNullOrWhiteSpace(customerId))
                        {
                            // Add the customer identifier to the claims
                            context.AuthenticationTicket.Identity.AddClaim(new System.Security.Claims.Claim("CustomerId", userTenantId));
                        }
                    },
                    RedirectToIdentityProvider = (context) =>
                    {
                        string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
                        context.ProtocolMessage.RedirectUri           = appBaseUrl + "/";
                        context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
                        return(Task.FromResult(0));
                    }
                },
                TokenValidationParameters = new TokenValidationParameters
                {
                    SaveSigninToken = true,
                    ValidateIssuer  = false
                }
            });
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseController"/> class.
 /// </summary>
 protected BaseController(IExplorerProvider provider)
 {
     this.provider = provider;
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvoicesController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public InvoicesController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RedisCacheProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core report providers.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public RedisCacheProvider(IExplorerProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyVaultProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core explorer providers.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public KeyVaultProvider(IExplorerProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionsController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public SubscriptionsController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OfferController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public OfferController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DomainsController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public DomainsController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuditController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public AuditController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CustomersController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public CustomersController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #17
0
ファイル: Users.cs プロジェクト: tmrconsultweb/TMRC-CSP
 public Users(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #18
0
 /// <summary>
 /// Initializes a new instance of <see cref="AccessTokenProvider"/> class.
 /// </summary>
 /// <param name="provider">Provides access to core explorer providers.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public AccessTokenProvider(IExplorerProvider provider)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
 }
コード例 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HealthController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public HealthController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ManageController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public ManageController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceRequestsController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public ServiceRequestsController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationProvider"/> class.
 /// </summary>
 /// <param name="service">Provides access to core explorer providers.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="service"/> is null.
 /// </exception>
 public ConfigurationProvider(IExplorerProvider service)
 {
     service.AssertNotNull(nameof(service));
     this.service = service;
 }
コード例 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 public HomeController(IExplorerProvider provider) : base(provider)
 {
 }
コード例 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceCommunications" /> class.
 /// </summary>
 /// <param name="provider">Provides access to core services.</param>
 /// <param name="token">Access token to be used for the requests.</param>
 /// <exception cref="System.ArgumentException">
 /// <paramref name="token"/> is null.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="provider"/> is null.
 /// </exception>
 public ServiceCommunications(IExplorerProvider provider, AuthenticationResult token)
 {
     provider.AssertNotNull(nameof(provider));
     this.provider = provider;
     this.token    = token;
 }
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UsersController"/> class.
 /// </summary>
 /// <param name="service">Provides access to core services.</param>
 public UsersController(IExplorerProvider provider) : base(provider)
 {
 }