Beispiel #1
0
        public Client Client(
            bool requireConsent = false,
            bool allowAccessTokensViaBrowser = true,
            int accessTokenLifetime          = 43200)
        {
            var client = new Client
            {
                RequireConsent    = requireConsent,
                ClientId          = Id,
                ClientName        = Name,
                ClientSecrets     = new List <Secret>(),
                AllowedGrantTypes = GrantTypes.Implicit,
                AllowedScopes     =
                {
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                },
                RedirectUris                = RedirectUris.ToList(),
                PostLogoutRedirectUris      = PostLogoutRedirectUris.ToList(),
                AllowedCorsOrigins          = AllowedCorsOrigins.ToList(),
                AllowAccessTokensViaBrowser = allowAccessTokensViaBrowser,
                AccessTokenLifetime         = accessTokenLifetime
            };

            foreach (string clientSecret in ClientSecrets)
            {
                client.ClientSecrets.Add(new Secret(clientSecret));
            }

            foreach (string allowedScope in AllowedScopes)
            {
                client.AllowedScopes.Add(allowedScope);
            }

            return(client);
        }
        public Client MapToClientEntity(string clientName)
        {
            var newClient = new Client
            {
                AllowedGrantTypes = GrantTypes.Code,
                ClientName        = clientName ?? Guid.NewGuid().ToString("N"),
                AllowedScopes     = DefaultScopes.Union(AllowedScopes).ToList(),
                AlwaysIncludeUserClaimsInIdToken = true,
                ClientId                         = $"CodeClientPKCE-{Guid.NewGuid():N}",
                ClientSecrets                    = new List <Secret>(),
                EnableLocalLogin                 = false,
                PostLogoutRedirectUris           = PostLogoutRedirectUris.ToList(),
                RedirectUris                     = RedirectUris.ToList(),
                UpdateAccessTokenClaimsOnRefresh = true,
                FrontChannelLogoutUri            = FrontChannelLogoutUri
            };

            if (AllowOfflineAccess == true)
            {
                newClient.AllowOfflineAccess           = true;
                newClient.AbsoluteRefreshTokenLifetime = Convert.ToInt32(TimeSpan.FromDays(OfflineAccessDurationInDays.Value).TotalSeconds);
                newClient.RefreshTokenUsage            = TokenUsage.ReUse;
                newClient.RefreshTokenExpiration       = TokenExpiration.Absolute;
            }

            if (AccessTokenLifetimeInSeconds.HasValue)
            {
                newClient.AccessTokenLifetime = AccessTokenLifetimeInSeconds.Value;
            }

            if (ShouldUseMfa)
            {
                newClient.Properties.Add(Constants.ShouldUseMfaKey, "true");
            }

            return(newClient);
        }
Beispiel #3
0
        public override async Task Execute()
        {
            await Authorize();

            if (string.IsNullOrEmpty(Id))
            {
                return;
            }
            Guid g;

            if (Guid.TryParse(Id, out g))
            {
                var apps = await SimpleClient.Apps();

                var app = (from a in apps.Response.Data where a.Id == g select a).FirstOrDefault();
                if (app == null)
                {
                    Log.Debug("Could not find app with the id:{0}", g);
                    return;
                }
                var updateApp = false;
                if (!string.IsNullOrEmpty(Name))
                {
                    app.Name  = Name;
                    updateApp = true;
                }
                if (!string.IsNullOrEmpty(Description))
                {
                    app.Description = Description;
                    updateApp       = true;
                }
                if (RedirectUris != null && RedirectUris.Length > 0)
                {
                    app.RedirectUris = RedirectUris.ToList();
                    updateApp        = true;
                }
                if (updateApp)
                {
                    var result = await SimpleClient.UpdateApp(app);

                    Log.Debug(result);
                }
                if (!string.IsNullOrEmpty(Image) && File.Exists(Image))
                {
                    Log.Debug("Updating app image");
                    var image       = File.ReadAllBytes(Image);
                    var fi          = new FileInfo(Image);
                    var imageResult = await SimpleClient.SaveImage(ImageEntities.Apps, g, image, fi.Name, "image/" + fi.Extension);

                    Log.Debug(imageResult);

                    if (imageResult.Success)
                    {
                        var images = await SimpleClient.GetImage(ImageEntities.Apps, g);

                        Log.Debug(images);
                    }
                }
            }
            else
            {
                Log.Debug("Invalid app id specified");
            }
            UpdateAuthorization();
        }