/// <summary> /// Creates a new instance of the object used to interface with Partner Center. /// </summary> /// <param name="context">The partner's execution context.</param> /// <returns>An instance of the <see cref="PartnerOperations" /> class.</returns> /// <exception cref="System.ArgumentNullException"> /// <paramref name="context" /> is null. /// </exception> public virtual IPartner CreatePartnerOperations(PartnerContext context) { AuthenticationResult authResult; context.AssertNotNull(nameof(context)); try { authResult = PartnerSession.Instance.AuthenticationFactory.Authenticate( context, null); IPartnerCredentials credentials = PartnerCredentials.Instance.GenerateByUserCredentials( context.ApplicationId, new AuthenticationToken(authResult.AccessToken, authResult.ExpiresOn)); PartnerService.Instance.ApplicationName = "Partner Center PowerShell (Preview)"; return(PartnerService.Instance.CreatePartnerOperations(credentials)); } finally { authResult = null; } }
/// <summary> /// Creates a new instance of the object used to interface with Partner Center. /// </summary> /// <param name="context">The partner's execution context.</param> /// <returns>An instance of the <see cref="PartnerOperations" /> class.</returns> /// <exception cref="System.ArgumentNullException"> /// <paramref name="context" /> is null. /// </exception> public virtual IAggregatePartner CreatePartnerOperations(PartnerContext context) { context.AssertNotNull(nameof(context)); return(PartnerService.Instance.CreatePartnerOperations( new PowerShellCredentials( PartnerSession.Instance.AuthenticationFactory.Authenticate(context)))); }
/// <summary> /// Authenticates the user using the specified parameters. /// </summary> /// <param name="context">The partner's execution context.</param> /// <param name="password">The password used to authenicate the user. This value can be null.</param> /// <returns>The result from the authentication request.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> is null. /// </exception> public AuthenticationResult Authenticate(PartnerContext context, SecureString password) { AuthenticationContext authContext; AuthenticationResult authResult; PartnerEnvironment environment; context.AssertNotNull(nameof(context)); try { environment = PartnerEnvironment.PublicEnvironments[context.Environment]; authContext = new AuthenticationContext($"{environment.ActiveDirectoryAuthority}{context.TenantId}"); if (string.IsNullOrEmpty(context.Username)) { authResult = authContext.AcquireToken( environment.PartnerCenterEndpoint, context.ApplicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior.Always, UserIdentifier.AnyUser); context.TenantId = authResult.TenantId; context.Username = authResult.UserInfo.DisplayableId; } else if (password != null) { authResult = authContext.AcquireToken( environment.PartnerCenterEndpoint, context.ApplicationId, new UserCredential( context.Username, password)); context.TenantId = authResult.TenantId; context.Username = authResult.UserInfo.DisplayableId; } else { authResult = authContext.AcquireToken( environment.PartnerCenterEndpoint, context.ApplicationId, new Uri("urn:ietf:wg:oauth:2.0:oob"), PromptBehavior.Never, new UserIdentifier(context.Username, UserIdentifierType.RequiredDisplayableId)); } return(authResult); } finally { authContext = null; environment = null; } }
/// <summary> /// Authenticates the user using the specified parameters. /// </summary> /// <param name="context">The partner's execution context.</param> /// <param name="password">The password used to authenicate the user. This value can be null.</param> /// <returns>The result from the authentication request.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> is null. /// </exception> public AuthenticationResult Authenticate(PartnerContext context, SecureString password) { context.AssertNotNull(nameof(context)); throw new NotImplementedException(); }