Esempio n. 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received a request to get api key credentials.");

            string              requestBody         = await new StreamReader(req.Body).ReadToEndAsync();
            DeveloperApp        apigeeDeveloperApp  = JsonConvert.DeserializeObject <DeveloperApp>(requestBody);
            AppRecentCredential appRecentCredential = null;

            if (apigeeDeveloperApp != null)
            {
                var credential = apigeeDeveloperApp.Credentials.OrderByDescending(p => DateTimeOffset.FromUnixTimeMilliseconds(p.IssuedAt)).First();
                if (credential != null)
                {
                    appRecentCredential = new AppRecentCredential
                    {
                        AppName        = apigeeDeveloperApp.Name,
                        APIKey         = credential.ConsumerKey,
                        DaysToExpiry   = (DateTimeOffset.FromUnixTimeMilliseconds(credential.ExpiresAt).UtcDateTime - DateTime.UtcNow).Days,
                        ExpirationDate = DateTimeOffset.FromUnixTimeMilliseconds(credential.ExpiresAt).UtcDateTime.ToShortDateString()
                    };
                }
            }
            string responseMessage = $" APIGEE API key {appRecentCredential.APIKey} is expiring on {appRecentCredential.ExpirationDate}";

            return(new OkObjectResult(appRecentCredential));
        }
Esempio n. 2
0
        private ViewAppViewModel(DeveloperUser user, DeveloperApp thisApp) : base(user)
        {
            if (thisApp.CreatorId != user.Id)
            {
                throw new InvalidOperationException("The app is not the user's app!");
            }
            AppName             = thisApp.AppName;
            AppDescription      = thisApp.AppDescription;
            AppCategory         = thisApp.AppCategory;
            AppPlatform         = thisApp.AppPlatform;
            AppId               = thisApp.AppId;
            AppSecret           = thisApp.AppSecret;
            EnableOAuth         = thisApp.EnableOAuth;
            ForceInputPassword  = thisApp.ForceInputPassword;
            ForceConfirmation   = thisApp.ForceConfirmation;
            DebugMode           = thisApp.DebugMode;
            PrivacyStatementUrl = thisApp.PrivacyStatementUrl;
            LicenseUrl          = thisApp.LicenseUrl;
            IconPath            = thisApp.IconPath;
            AppDomain           = thisApp.AppDomain;
            AppFailCallbackUrl  = thisApp.AppFailCallbackUrl;

            ViewOpenId          = thisApp.ViewOpenId;
            ViewPhoneNumber     = thisApp.ViewPhoneNumber;
            ChangePhoneNumber   = thisApp.ChangePhoneNumber;
            ConfirmEmail        = thisApp.ConfirmEmail;
            ChangeBasicInfo     = thisApp.ChangeBasicInfo;
            ChangePassword      = thisApp.ChangePassword;
            ChangeGrantInfo     = thisApp.ChangeGrantInfo;
            ViewAuditLog        = thisApp.ViewAuditLog;
            ManageSocialAccount = thisApp.ManageSocialAccount;
        }
Esempio n. 3
0
        public async Task Recover(
            DeveloperUser user,
            DeveloperApp appInDb,
            CoreApiService coreApiService,
            AppsContainer appsContainer,
            SitesService sitesService,
            EventService eventService,
            ChannelService channelService,
            RecordsService recordsService,
            int pageNumber)
        {
            RootRecover(user);
            var token = await appsContainer.AccessToken(appInDb.AppId, appInDb.AppSecret);

            Grants = await coreApiService.AllUserGrantedAsync(token, pageNumber, 15);

            var sites = await sitesService.ViewMySitesAsync(token);

            Sites = sites.Sites;

            var errorLogs = await eventService.ViewAsync(token);

            ErrorLogs = errorLogs.Logs;

            var channels = await channelService.ViewMyChannelsAsync(token);

            Channels = channels.Channels;

            var records = await recordsService.ViewMyRecordsAsync(token, Array.Empty <string>());

            Records = records.Records;

            Trusted = appInDb.TrustedApp;
        }
Esempio n. 4
0
 public static async Task <IActionResult> Run(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
     ILogger log)
 {
     log.LogInformation("Received a request to compose json for creating new APIGEE API Credential");
     try
     {
         string            requestBody          = await new StreamReader(req.Body).ReadToEndAsync();
         DeveloperApp      developerApp         = JsonConvert.DeserializeObject <DeveloperApp>(requestBody);
         DateTimeOffset    expiryDateTimeOffset = DateTimeOffset.MinValue;
         AppNewCrendential apiKeyCrendential    = new AppNewCrendential();
         if (developerApp != null)
         {
             apiKeyCrendential.Name         = developerApp.Name;
             apiKeyCrendential.KeyExpiresIn = Convert.ToInt64(TimeSpan.FromHours(90 * 24).TotalMilliseconds);
             apiKeyCrendential.ApiProducts  = new List <string>();
             foreach (var item in developerApp.Credentials)
             {
                 foreach (var product in item.ApiProducts)
                 {
                     if (!apiKeyCrendential.ApiProducts.Contains(product.Apiproduct))
                     {
                         apiKeyCrendential.ApiProducts.Add(product.Apiproduct);
                     }
                 }
             }
         }
         return(new OkObjectResult(JsonConvert.SerializeObject(apiKeyCrendential)));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 5
0
        public static async Task <ViewAppViewModel> SelfCreateAsync(
            DeveloperUser user,
            DeveloperApp appInDb,
            CoreApiService coreApiService,
            AppsContainer appsContainer,
            SitesService sitesService,
            EventService eventService,
            ChannelService channelService,
            int pageNumber)
        {
            var model = new ViewAppViewModel(user, appInDb);
            await model.Recover(user, appInDb, coreApiService, appsContainer, sitesService, eventService, channelService, pageNumber);

            return(model);
        }
Esempio n. 6
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var currentUser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.RootRecover(currentUser);
                return(View(model));
            }
            var newApp = new DeveloperApp(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform, model.IconPath)
            {
                CreatorId = currentUser.Id
            };
            await _dbContext.Apps.AddAsync(newApp);

            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = newApp.AppId }));
        }