Example #1
0
        internal override async Task <bool> ValidateDeviceAsync(Account user)
        {
            SystemSignInData data = Context.OwinContext.Get <SystemSignInData>("systemSignInData") ?? new SystemSignInData {
            };

            if ((object.Equals(data, null)) || (data.MachineKey == Guid.Empty &&
                                                string.IsNullOrEmpty(data.MotherboardKey) &&
                                                string.IsNullOrEmpty(data.PhysicalMac)))
            {
                Context.SetError("invalid_grant", "System is null or empty.");
                return(false);
            }

            var system = await Auth.SystemInsertAsync(new Data.Entities.Oauth.OauthSystem
            {
                MachineKey                = data.MachineKey,
                MotherboardKey            = data.MotherboardKey,
                PhysicalMac               = data.PhysicalMac,
                IsAutogeneratedMachineKey = data.IsAutogeneratedMachineKey,
                PcName = data.PcName
            });

            Context.OwinContext.Set("systemId", system.Id);

            return(true);
        }
        public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
        {
            string clientId, clientSecret;

            if (!context.TryGetBasicCredentials(out clientId, out clientSecret))
            {
                context.TryGetFormCredentials(out clientId, out clientSecret);
            }

            var client = ValidateClientAuthentication(context, clientSecret);

            if (object.Equals(client, null))
            {
                return;
            }

            string[]         scope            = null;
            SystemSignInData systemSignInData = null;
            string           token            = null;

            var formCollection = await context.Request.ReadFormAsync();

            if (!object.Equals(formCollection, null))
            {
                scope            = GetScope(formCollection);
                systemSignInData = GetSystemSignInData(formCollection);
                token            = formCollection["token"];

                Guid visitorId;
                if (Guid.TryParse(formCollection["visitorId"], out visitorId))
                {
                    context.OwinContext.Set("visitorId", visitorId);
                }

                var externalClient = OauthManager.GetExternalClient(formCollection["externalClient"]);
                if (externalClient.HasValue)
                {
                    context.OwinContext.Set("externalClient", externalClient);
                }

                Version clientVersion;
                if ((Version.TryParse(formCollection["client_version"], out clientVersion) && clientVersion.Major > 0) ||
                    Version.TryParse(client.Version, out clientVersion))
                {
                    context.OwinContext.Set("clientVersion", clientVersion.ToString());
                }

                if (Guid.TryParse(formCollection["installationID"], out Guid installationID))
                {
                    context.OwinContext.Set("installationID", installationID);
                }
            }

            context.OwinContext.Set("scope", scope);
            context.OwinContext.Set("systemSignInData", systemSignInData);
            context.OwinContext.Set("client", client);
            context.OwinContext.Set("token", token);

            context.Validated();
        }
        private SystemSignInData GetSystemSignInData(IFormCollection formCollection)
        {
            var systemSignInData = new SystemSignInData
            {
                MotherboardKey = formCollection["motherboardKey"],
                PhysicalMac    = formCollection["physicalMac"],
                PcName         = formCollection["pcName"] ?? null
            };

            Guid machineKey;

            if (Guid.TryParse(formCollection["machineKey"], out machineKey))
            {
                systemSignInData.MachineKey = machineKey;
            }

            bool isAutogeneratedMachineKey;

            bool.TryParse(formCollection["isAutogeneratedMachineKey"], out isAutogeneratedMachineKey);
            systemSignInData.IsAutogeneratedMachineKey = isAutogeneratedMachineKey;

            return(systemSignInData);
        }