Beispiel #1
0
 public static async Task <HttpResponseMessage> CreateResponseAsync(
     [QueryParameter(Name = "login_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                async (document) =>
     {
         var providerKvp = await application.AuthorizationProviders
                           .Where(prov => prov.Value.GetType().FullName == document.Provider)
                           .FirstAsync(
             value => value,
             () => default(KeyValuePair <string, IProvideAuthorization>));
         var provider = providerKvp.Value;
         Enum.TryParse(document.Action, out AuthenticationActions action);
         return await ResponseController.CreateResponse(application, provider, document.Method, action,
                                                        document.SessionId, document.AuthorizationId, document.Token, document.RefreshToken,
                                                        document.GetValuesCredential(), request.RequestUri,
                                                        document.RedirectUrl.IsNullOrWhiteSpace(
                                                            () => null,
                                                            redirUrlString => new Uri(redirUrlString)),
                                                        (redirectUri, message) => redirectResponse(redirectUri),
                                                        (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                        application.Telemetry);
     },
                                                                () => viewResponse("", null).AsTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }
Beispiel #2
0
        public async Task <TResult> SendEmailInviteAsync <TResult>(Guid inviteId, Guid actorId, string email,
                                                                   EastFive.Api.Azure.AzureApplication application, Guid performingActorId, System.Security.Claims.Claim[] claims,
                                                                   Func <Guid, Guid, Uri> getRedirectLink,
                                                                   Func <TResult> success,
                                                                   Func <TResult> inviteAlreadyExists,
                                                                   Func <TResult> onCredentialMappingDoesNotExists,
                                                                   Func <TResult> onUnauthorized,
                                                                   Func <TResult> onServiceNotAvailable,
                                                                   Func <string, TResult> onFailed)
        {
            if (!await Library.configurationManager.CanAdministerCredentialAsync(actorId, performingActorId, claims))
            {
                return(onUnauthorized());
            }

            var token   = SecureGuid.Generate();
            var loginId = Guid.NewGuid(); // This creates a "user" in the invite system
            var result  = await await this.dataContext.CredentialMappings.CreateCredentialMappingAsync(inviteId,
                                                                                                       loginId, actorId, email, token, DateTime.UtcNow, false, false,
                                                                                                       async() =>
            {
                var templateName = ConfigurationManager.AppSettings[Configuration.EmailTemplateDefinitions.InviteNewAccount];
                if (string.IsNullOrEmpty(templateName))
                {
                    return(onFailed($"Email template setting not found.  Expected template value for key {Configuration.EmailTemplateDefinitions.InviteNewAccount}"));
                }

                var resultMail = await application.SendMessageService.SendEmailMessageAsync(templateName,
                                                                                            email, string.Empty,
                                                                                            "*****@*****.**", "New Account Services",
                                                                                            "New Order Owl Account",
                                                                                            new Dictionary <string, string>()
                {
                    { "create_account_link", getRedirectLink(inviteId, token).AbsoluteUri }
                },
                                                                                            null,
                                                                                            (sentCode) => success(),
                                                                                            () => onServiceNotAvailable(),
                                                                                            (why) => onFailed(why));
                return(resultMail);
            },
                                                                                                       () => inviteAlreadyExists().ToTask(),
                                                                                                       () => { throw new Exception("Token generated was not unique"); },
                                                                                                       () => { throw new Exception("Login Id generated was not unique"); });

            return(result);
        }
Beispiel #3
0
 public static Task <HttpResponseMessage> CreateAsync(
     [Property(Name = Resources.ProcessStage.IdPropertyName)]
     Guid processStageId,
     [Property(Name = Resources.ProcessStage.OwnerPropertyName)]
     Guid ownerId,
     [Property(Name = Resources.ProcessStage.TypePropertyName)]
     Guid processStageTypeId,
     [PropertyOptional(Name = Resources.ProcessStage.TitlePropertyName)]
     string title,
     [PropertyOptional(Name = Resources.ProcessStage.ViewablePropertyName)]
     Guid [] viewableIds,
     [PropertyOptional(Name = Resources.ProcessStage.CompletablePropertyName)]
     Guid [] completableIds,
     [PropertyOptional(Name = Resources.ProcessStage.EditablePropertyName)]
     Guid [] editableIds,
     [PropertyOptional(Name = Resources.ProcessStage.ConfirmablePropertyName)]
     Resources.ProcessStage.ConfirmableResource [] confirmables,
     EastFive.Api.Security security, EastFive.Api.Azure.AzureApplication application,
     CreatedResponse onCreated,
     AlreadyExistsResponse onAlreadyExists,
     ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStageType> onTypeDoesNotExist,
     ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onConfirmationStageDoesNotExist,
     ReferencedDocumentDoesNotExistsResponse <BlackBarLabs.Api.ResourceBase> onActorDoesNotExists,
     UnauthorizedResponse onUnauthorized,
     GeneralConflictResponse onFailure)
 {
     return(EastFive.Azure.ProcessStages.CreateAsync(processStageId, ownerId, processStageTypeId, title,
                                                     viewableIds, editableIds, completableIds,
                                                     confirmables
                                                     .Select(
                                                         confirmable =>
                                                         confirmable.ProcessStageNext.ToGuid().Value
                                                         .PairWithKey(
                                                             confirmable.Positions
                                                             .Select(position => position.ToGuid().Value)
                                                             .ToArray()))
                                                     .ToArray(),
                                                     security,
                                                     () => onCreated(),
                                                     () => onAlreadyExists(),
                                                     () => onTypeDoesNotExist(),
                                                     (missingStageId) => onConfirmationStageDoesNotExist(),
                                                     () => onActorDoesNotExists(),
                                                     (why) => onFailure(why)));
 }
Beispiel #4
0
 public static async Task <HttpResponseMessage> ReplicateLogin(
     [QueryParameter(Name = "credential_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                (document) =>
     {
         return ResponseController.ProcessRequestAsync(application, document.Method, request.RequestUri, document.GetValuesCredential(),
                                                       (redirectUri, message) => redirectResponse(redirectUri),
                                                       (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null));
     },
                                                                () => viewResponse("", null).ToTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }
Beispiel #5
0
        public static async Task <HttpResponseMessage> SessionManagement(
            [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
            ApiSecurity apiSecurity,
            EastFive.Api.Azure.AzureApplication application,
            UnauthorizedResponse onUnauthorized,
            ViewFileResponse viewResponse)
        {
            return(await await CredentialProcessDocument.FindAllAsync(
                       async documents =>
            {
                var orderedDocs = documents.OrderByDescending(doc => doc.Time).Take(1000).ToArray();

                var details = new SessionManagementDetails()
                {
                };
                details.CredentialDocuments = orderedDocs;
                details.AccountIdToNameLookup = await orderedDocs
                                                .Select(doc => doc.AuthorizationId)
                                                .Distinct()
                                                .Select(
                    async authId =>
                {
                    var fullName = await application.GetActorNameDetailsAsync(authId,
                                                                              (username, firstName, lastName) =>
                    {
                        return $"{firstName} {lastName}";
                    },
                                                                              () => string.Empty);
                    return fullName.PairWithKey(authId);
                })
                                                .AsyncEnumerable()
                                                .ToDictionaryAsync();

                return viewResponse("/SessionManagement/Index.cshtml", details);
            },
                       BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                           EastFive.Azure.AppSettings.ASTConnectionStringKey)));
        }
Beispiel #6
0
 public static async Task <HttpResponseMessage> RedeemAsync(
     [QueryParameter(Name = "redemption_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                async (document) =>
     {
         var context = application.AzureContext;
         var responseParameters = document.GetValuesCredential();
         var providerKvp = await application.AuthorizationProviders
                           .Where(prov => prov.Value.GetType().FullName == document.Provider)
                           .FirstAsync(
             value => value,
             () => default(KeyValuePair <string, IProvideAuthorization>));
         var provider = providerKvp.Value;
         return await provider.ParseCredentailParameters(responseParameters,
                                                         async(subject, stateId, loginId) => await await context.Sessions.TokenRedeemedAsync <Task <HttpResponseMessage> >(
                                                             document.Method, provider, subject, stateId, loginId, responseParameters,
                                                             (sessionId, authorizationId, token, refreshToken, actionReturned, providerReturned, extraParams, redirectUrl) =>
         {
             return ResponseController.CreateResponse(application, providerReturned, document.Method, actionReturned, sessionId, authorizationId,
                                                      token, refreshToken, extraParams, request.RequestUri, redirectUrl,
                                                      (redirectUri, message) => redirectResponse(redirectUri),
                                                      (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                      application.Telemetry);
         },
                                                             async(redirectUrl, reason, providerReturned, extraParams) =>
         {
             if (redirectUrl.IsDefaultOrNull())
             {
                 return Web.Configuration.Settings.GetUri(Security.SessionServer.Configuration.AppSettings.LandingPage,
                                                          (redirect) => redirectResponse(redirectUrl),
                                                          (why) => viewResponse($"<html><head><title>{reason}</title></head><body>{why}</body></html>", null));
             }
             if (redirectUrl.Query.IsNullOrWhiteSpace())
             {
                 redirectUrl = redirectUrl.SetQueryParam("cache", Guid.NewGuid().ToString("N"));
             }
             return await redirectResponse(redirectUrl).AsTask();
         },
                                                             (subjectReturned, credentialProvider, extraParams, createMappingAsync) =>
         {
             return ResponseController.UnmappedCredentailAsync(application,
                                                               credentialProvider, document.Method, subjectReturned, extraParams, request.RequestUri,
                                                               createMappingAsync,
                                                               (redirectUri, message) => redirectResponse(redirectUri),
                                                               (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                               application.Telemetry).ToTask();
         },
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             application.Telemetry),
                                                         (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask());
     },
                                                                () => viewResponse("", null).ToTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }