Beispiel #1
0
        /// <summary>
        ///     Returns true if MsalAuthParameters instances are equal
        /// </summary>
        /// <param name="other">Instance of MsalAuthParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(MsalAuthParameters other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((ClientApplicationId == other.ClientApplicationId ||
                  ClientApplicationId != null && ClientApplicationId.Equals(other.ClientApplicationId)) &&
                 (ClientId == other.ClientId || ClientId != null && ClientId.Equals(other.ClientId)) &&
                 (Authority == other.Authority || Authority != null && Authority.Equals(other.Authority)) &&
                 (RedirectUri == other.RedirectUri || RedirectUri != null && RedirectUri.Equals(other.RedirectUri)) &&
                 (RequestedScopes == other.RequestedScopes ||
                  RequestedScopes != null && RequestedScopes.Equals(other.RequestedScopes)) &&
                 (Username == other.Username || Username != null && Username.Equals(other.Username)) &&
                 (Password == other.Password || Password != null && Password.Equals(other.Password)) &&
                 (TelemetryCorrelationId == other.TelemetryCorrelationId || TelemetryCorrelationId != null &&
                  TelemetryCorrelationId.Equals(other.TelemetryCorrelationId)) &&
                 (AuthorizationType == other.AuthorizationType ||
                  AuthorizationType != null && AuthorizationType.Equals(other.AuthorizationType)));
        }
Beispiel #2
0
        /// <summary>
        /// Gets revit application.
        /// </summary>
        /// <returns></returns>
        public Application GetApplication()
        {
            var clientId = new ClientApplicationId(Guid.NewGuid(), _clientName, _vendorId);

            _product = Product.GetInstalledProduct();

            // The string must be this 'I am authorized by Autodesk to use this UI-less functionality.'.
            _product.Init(clientId, "I am authorized by Autodesk to use this UI-less functionality.");

            return(_product.Application);
        }
Beispiel #3
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (ClientApplicationId != null)
                {
                    hashCode = hashCode * 59 + ClientApplicationId.GetHashCode();
                }

                if (ClientId != null)
                {
                    hashCode = hashCode * 59 + ClientId.GetHashCode();
                }

                if (Authority != null)
                {
                    hashCode = hashCode * 59 + Authority.GetHashCode();
                }

                if (RedirectUri != null)
                {
                    hashCode = hashCode * 59 + RedirectUri.GetHashCode();
                }

                if (RequestedScopes != null)
                {
                    hashCode = hashCode * 59 + RequestedScopes.GetHashCode();
                }

                if (Username != null)
                {
                    hashCode = hashCode * 59 + Username.GetHashCode();
                }

                if (Password != null)
                {
                    hashCode = hashCode * 59 + Password.GetHashCode();
                }

                if (TelemetryCorrelationId != null)
                {
                    hashCode = hashCode * 59 + TelemetryCorrelationId.GetHashCode();
                }

                if (AuthorizationType != null)
                {
                    hashCode = hashCode * 59 + AuthorizationType.GetHashCode();
                }

                return(hashCode);
            }
        }
Beispiel #4
0
        public MainWindow()
        {
            InitializeComponent();

            if (Directory.Exists(RevitFolder))
            {
                var product  = Product.GetInstalledProduct();
                var clientId = new ClientApplicationId(Guid.NewGuid(), "DotNet", "BIMAPI");

                // I am authorized by Autodesk to use this UI-less functionality. 必须是此字符串。为啥? Autodesk 规定的.
                product.Init(clientId, "I am authorized by Autodesk to use this UI-less functionality.");
                m_App = product.Application;
            }
        }
Beispiel #5
0
        public void convertRevitFiles()
        {
            Product _product = Product.GetInstalledProduct();

            var clientId = new ClientApplicationId(Guid.NewGuid(), "LK", "BIMAPI");

            //"I am authorized by Autodesk to use this UI-less functionality."
            _product.Init(clientId, "I am authorized by Autodesk to use this UI-less functionality.");

            foreach (RevitFileUtils file in files)
            {
                convertRevitFile(file.getFilePath(), _product, file.getBuildingName());
            }
            _product?.Exit();
        }
Beispiel #6
0
        public void InitRevit()
        {
            this.OpenOptions = new OpenOptions
            {
                Audit = true,
                AllowOpeningLocalByWrongUser = false,
                DetachFromCentralOption      = DetachFromCentralOption.DetachAndDiscardWorksets //从中心模型分离
            };
            _revitProduct = Product.GetInstalledProduct();
            var clientApplicationId = new ClientApplicationId(Guid.NewGuid(), "RevitContext", "BIM");

            _revitProduct.SetPreferredLanguage(Autodesk.Revit.ApplicationServices.LanguageType.Chinese_Simplified);
            _revitProduct.Init(clientApplicationId, "I am authorized by Autodesk to use this UI-less functionality.");
            OnInitRevitFinished();
        }
        public async Task UserNamePasswordAndRefreshTokenHappyFlowWithRole()
        {
            await this.identityInstance.RoleManager.CreateAsync(new AppRole
            {
                Name = TestRole,
            }).ConfigureAwait(true);

            var user = await this.identityInstance.CreateUserAsync(UserName).ConfigureAwait(true);

            await this.identityInstance.UserManager.AddToRoleAsync(user, TestRole).ConfigureAwait(true);

            var authenticationResult =
                await this.authenticationFlow.TryAuthenticateUsingUserNameAndPasswordAsync(
                    UserName,
                    Password,
                    true,
                    this.identityInstance.ClientId,
                    FlowConcurrencyStamp,
                    CancellationToken.None)
                .ConfigureAwait(true);

            authenticationResult.Should().NotBeNull(because: "the sign-in attempt should have succeeded");
            authenticationResult !.ClientApplicationId.Should().Be(
                this.identityInstance.ClientId,
                because: "the client identifier should be echoed");
            authenticationResult.ConcurrencyStamp.Should().Be(
                FlowConcurrencyStamp,
                because: "the concurrency stamp should be echoed");
            authenticationResult.RefreshToken.Should().NotBeEmpty(because: "a refresh token was requested");

            this.ValidateBearer(authenticationResult.BearerToken, user.Id);

            var refreshTokenBinary = Convert.FromBase64String(authenticationResult.RefreshToken !);

            var refreshTokenEntity = await this.dbContext.UserRefreshTokens.FindAsync(refreshTokenBinary)
                                     .ConfigureAwait(true);

            refreshTokenEntity.Should().NotBeNull(because: "the refresh token must be persisted");
            refreshTokenEntity.ExpiresAtUtc.Should().Be(this.momentMock.Object.UtcNow.AddDays(28));
            refreshTokenEntity.SubjectUserId.Should().Be(user.Id, because: "the refresh token must be linked to the user");
            refreshTokenEntity.IsInvalidated.Should().BeFalse(because: "the refresh token is not used or invalidated");

            authenticationResult =
                await this.authenticationFlow.TryAuthenticateUsingRefreshTokenAsync(
                    authenticationResult.RefreshToken !,
                    false,
                    this.identityInstance.ClientId,
                    FlowConcurrencyStamp,
                    CancellationToken.None)
                .ConfigureAwait(true);

            authenticationResult.Should().NotBeNull(because: "the sign-in attempt should have succeeded");
            authenticationResult !.ClientApplicationId.Should().Be(
                this.identityInstance.ClientId,
                because: "the client identifier should be echoed");
            authenticationResult.ConcurrencyStamp.Should().Be(
                FlowConcurrencyStamp,
                because: "the concurrency stamp should be echoed");
            authenticationResult.RefreshToken.Should().BeEmpty(because: "no refresh token was requested");

            this.ValidateBearer(authenticationResult.BearerToken, user.Id, TestRole);

            refreshTokenEntity = await this.dbContext.UserRefreshTokens.FindAsync(refreshTokenBinary)
                                 .ConfigureAwait(true);

            refreshTokenEntity.IsInvalidated.Should().BeTrue(because: "the refresh token was used and therefore invalidated");
        }