public static async Task <HttpResponseMessage> GetAllSecureAsync(
     [QueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     [QueryParameter(Name = "authorization")] IRef <Authorization> authorizationRef,
     ApiSecurity apiSecurity,
     AzureApplication application,
     HttpRequestMessage request,
     MultipartResponseAsync <Authorization> onContent,
     RedirectResponse onSuccess,
     NotFoundResponse onNotFound,
     ForbiddenResponse onFailure)
 {
     return(await await authorizationRef.StorageGetAsync(
                async authorization =>
     {
         return await await Method.ById(authorization.Method, application,
                                        async method =>
         {
             return await await method.ParseTokenAsync(authorization.parameters, application,
                                                       (externalId, loginProvider) =>
             {
                 return Auth.Redirection.ProcessAsync(authorization,
                                                      async updatedAuth =>
                 {
                 }, method, externalId, authorization.parameters,
                                                      Guid.NewGuid(), request.RequestUri, application, loginProvider,
                                                      (uri) => onSuccess(uri),
                                                      (why) => onFailure().AddReason(why),
                                                      application.Telemetry);
             },
                                                       why => onFailure().AddReason(why).AsTask());
         },
                                        () => onFailure().AddReason("Method no longer supported").AsTask());
     },
                () => onNotFound().AsTask()));
 }
 [Api.HttpPost] //(MatchAllBodyParameters = false)]
 public async static Task <HttpResponseMessage> CreateAsync(
     [Property(Name = AccountPropertyName)] Guid accountId,
     [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef,
     [Resource] AccountMapping accountMapping,
     Api.Azure.AzureApplication application, Api.SessionToken security,
     CreatedResponse onCreated,
     ForbiddenResponse onForbidden,
     UnauthorizedResponse onUnauthorized,
     ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist,
     GeneralConflictResponse onFailure)
 {
     if (!await application.CanAdministerCredentialAsync(accountId, security))
     {
         return(onUnauthorized());
     }
     return(await await authorizationRef.StorageGetAsync(
                async authorization =>
     {
         accountMapping.Method = authorization.Method;     // method is used in the .mappingId
         var authorizationLookup = new AuthorizationLookup
         {
             accountMappingRef = accountMapping.mappingId,
             authorizationLookupRef = authorizationRef,
         };
         return await await authorizationLookup.StorageCreateAsync(
             async(idDiscard) =>
         {
             accountMapping.accountMappingLookup = await await authorization.ParseCredentailParameters(
                 application,
                 (accountKey, loginProvider) =>
             {
                 var lookup = new AccountMappingLookup()
                 {
                     accountkey = accountKey,
                     accountMappingId = accountMapping.mappingId,
                     Method = authorization.Method,
                 };
                 return lookup.StorageCreateAsync(
                     (discard) => new RefOptional <AccountMappingLookup>(
                         lookup.accountMappingLookupId),
                     () => new RefOptional <AccountMappingLookup>());
             },
                 (why) =>
             {
                 var amLookupMaybe = new RefOptional <AccountMappingLookup>();
                 return amLookupMaybe.AsTask();
             });
             return await accountMapping.StorageCreateAsync(
                 createdId =>
             {
                 return onCreated();
             },
                 () => onForbidden().AddReason("Account is already mapped to that authentication."));
         },
             () => onFailure("Authorization is already mapped to another account.").AsTask());
     },
                () => onAuthenticationDoesNotExist().AsTask()));
 }
예제 #3
0
        public static async Task <IHttpResponse> ReplayAsync(
            [QueryId(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef,
            Api.Azure.AzureApplication application,
            IInvokeApplication endpoints,
            IHttpRequest request,
            ContentTypeResponse <Session> onReplayed,
            NotFoundResponse onNotFound,
            ForbiddenResponse onAuthorizationFailed,
            ServiceUnavailableResponse onServericeUnavailable,
            ForbiddenResponse onInvalidMethod,
            GeneralConflictResponse onFailure)
        {
            return(await await authorizationRef.StorageGetAsync(
                       async (authorization) =>
            {
                var methodRef = authorization.Method;
                return await await Auth.Method.ById(methodRef, application,
                                                    async(method) =>
                {
                    var paramsUpdated = authorization.parameters
                                        .Append(authorizationRef.id.ToString().PairWithKey("state"))
                                        .ToDictionary();

                    //var authorizationRequestManager = application.AuthorizationRequestManager;
                    return await await Redirection.AuthenticationAsync(
                        method,
                        paramsUpdated,
                        application, request,
                        endpoints,
                        request.RequestUri,
                        authorizationRef.Optional(),
                        async(redirect, accountIdMaybe, modifier) =>
                    {
                        var sessionRef = Ref <Session> .SecureRef();
                        var session = new Session()
                        {
                            sessionId = sessionRef,
                            account = accountIdMaybe,
                            authorization = authorizationRef.Optional(),
                        };
                        var responseCreated = await Session.CreateAsync(sessionRef, authorizationRef.Optional(),
                                                                        session,
                                                                        application,
                                                                        (sessionCreated, contentType) =>
                        {
                            var response = onReplayed(sessionCreated, contentType: contentType);
                            response.SetLocation(redirect);
                            return response;
                        },
                                                                        onAlreadyExists: default,
예제 #4
0
        [Api.HttpPatch] //(MatchAllBodyParameters = false)]
        public async static Task <IHttpResponse> UpdateAsync(
            [Property(Name = IntegrationIdPropertyName)] IRef <XIntegration> integrationRef,
            [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef,
            Api.Azure.AzureApplication application, EastFive.Api.SessionToken security,
            ContentTypeResponse <XIntegration> onUpdated,
            NotFoundResponse onNotFound,
            ForbiddenResponse onForbidden,
            ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist,
            UnauthorizedResponse onUnauthorized)
        {
            return(await integrationRef.StorageUpdateAsync(
                       async (integration, saveAsync) =>
            {
                var accountId = integration.accountId;
                if (!await application.CanAdministerCredentialAsync(accountId, security))
                {
                    return onUnauthorized();
                }

                return await await authorizationRef.StorageGetAsync(
                    async authorization =>
                {
                    if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization))
                    {
                        return onForbidden().AddReason("Authorization is not accessable to this account.");
                    }

                    integration.Method = authorization.Method;         // method is used in the .mappingId
                    integration.authorization = authorizationRef.Optional();
                    integration.methodName = await Auth.Method.ById(authorization.Method,
                                                                    application,
                                                                    method => method.name,
                                                                    () => string.Empty);

                    await saveAsync(integration);
                    return onUpdated(integration);
                },
                    () => onAuthorizationDoesNotExist().AsTask());
            },
                       () => onNotFound(),
                       onModificationFailures:
                       StorageConstraintUniqueAttribute.ModificationFailure(
                           (XIntegration x) => x.authorization,
                           () =>
            {
                // TODO: Check if mapping is to this integration and reply already created.
                return onForbidden().AddReason("Authorization is already in use.");
            }).AsArray()));
        }
        public async Task <IActionResult> UpdateCategoryAsync(int id, UpdateCategoryModel model)
        {
            if (GetUserId() != model.UserId || id != model.CategoryId)
            {
                var forbidden = new ForbiddenResponse();
                return(StatusCode(forbidden.Status, forbidden));
            }

            if (ModelState.IsValid)
            {
                var result = await _updateCategoryCommand.RunAsync(model);

                return(StatusCode(result.Status, result.Payload));
            }
            return(new BadRequestObjectResult(new BadRequestResponse(ModelState)));
        }
예제 #6
0
        public async Task <IActionResult> UpdateAccountAsync(string id, [FromBody] UpdateAccountModel model)
        {
            if (GetUserId() != id || GetUserId() != model.UserId)
            {
                var forbidden = new ForbiddenResponse();
                return(StatusCode(forbidden.Status, forbidden));
            }

            if (!ModelState.IsValid)
            {
                var result = await _updateAccountCommand.RunAsync(model);

                return(StatusCode(result.Status, result.Payload));
            }
            return(new BadRequestObjectResult(new BadRequestResponse(ModelState)));
        }
        public async Task <IActionResult> ChangePasswordAsync(string id, [FromBody] ChangePasswordModel model)
        {
            if (GetUserId() != model.UserId || GetUserId() != id)
            {
                var forbiddenResult = new ForbiddenResponse();
                return(StatusCode(forbiddenResult.Status, forbiddenResult));
            }

            if (ModelState.IsValid)
            {
                var result = await _changePasswordCommand.RunAsync(model);

                return(StatusCode(result.Status, result.Payload));
            }
            return(new BadRequestObjectResult(new BadRequestResponse(ModelState)));
        }
        [Api.HttpPatch] //(MatchAllBodyParameters = false)]
        public async static Task <HttpResponseMessage> UpdateAsync(
            [Property(Name = IntegrationIdPropertyName)] IRef <Integration> integrationRef,
            [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef,
            Api.Azure.AzureApplication application, EastFive.Api.SessionToken security,
            ContentTypeResponse <Integration> onUpdated,
            NotFoundResponse onNotFound,
            NotModifiedResponse onNotModified,
            ForbiddenResponse onForbidden,
            ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist,
            UnauthorizedResponse onUnauthorized)
        {
            return(await integrationRef.StorageUpdateAsync(
                       async (integration, saveAsync) =>
            {
                var accountId = integration.accountId;
                if (!await application.CanAdministerCredentialAsync(accountId, security))
                {
                    return onUnauthorized();
                }

                return await await authorizationRef.StorageGetAsync(
                    async authorization =>
                {
                    // TODO? This
                    // var accountIdDidMatch = await await authorization.ParseCredentailParameters(
                    integration.Method = authorization.Method;         // method is used in the .mappingId
                    integration.authorization = authorizationRef.Optional();
                    return await await SaveAuthorizationLookupAsync(integration.integrationRef, authorization.authorizationRef,
                                                                    async() =>
                    {
                        await saveAsync(integration);
                        return await SaveAccountLookupAsync(accountId, integration,
                                                            () => onUpdated(integration));
                    },
                                                                    () =>
                    {
                        // TODO: Check if mapping is to this integration and reply already created.
                        return onForbidden().AddReason("Authorization is already in use.").AsTask();
                    });
                },
                    () =>
                {
                    return onNotModified().AsTask();
                });
            },
                       () => onNotFound()));
        }
예제 #9
0
        [HttpPost] //(MatchAllBodyParameters = false)]
        public async static Task <HttpResponseMessage> CreateAsync(
            [Property(Name = SessionIdPropertyName)] IRef <Session> sessionId,
            [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe,
            [Resource] Session session,
            Api.Azure.AzureApplication application,
            CreatedBodyResponse <Session> onCreated,
            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse forbidden,
            ConfigurationFailureResponse onConfigurationFailure,
            GeneralConflictResponse onFailure)
        {
            session.refreshToken = Security.SecureGuid.Generate().ToString("N");

            return(await Security.AppSettings.TokenScope.ConfigurationUri(
                       scope =>
            {
                return Security.SessionServer.Configuration.AppSettings.TokenExpirationInMinutes.ConfigurationDouble(
                    async(tokenExpirationInMinutes) =>
                {
                    return await await GetClaimsAsync(application, authorizationRefMaybe,
                                                      (claims, accountIdMaybe, authorized) =>
                    {
                        session.account = accountIdMaybe;
                        session.authorized = authorized;
                        return session.StorageCreateAsync(
                            (sessionIdCreated) =>
                        {
                            return BlackBarLabs.Security.Tokens.JwtTools.CreateToken(sessionId.id,
                                                                                     scope, TimeSpan.FromMinutes(tokenExpirationInMinutes), claims,
                                                                                     (tokenNew) =>
                            {
                                session.token = tokenNew;
                                return onCreated(session);
                            },
                                                                                     (missingConfig) => onConfigurationFailure("Missing", missingConfig),
                                                                                     (configName, issue) => onConfigurationFailure(configName, issue));
                        },
                            () => onAlreadyExists());
                    },
                                                      (why) => onFailure(why).AsTask());
                },
                    (why) => onConfigurationFailure("Missing", why).AsTask());
            },
                       (why) => onConfigurationFailure("Missing", why).AsTask()));
        }
예제 #10
0
 public static Task <HttpResponseMessage> UpdateBodyAsync(
     [UpdateId(Name = SessionIdPropertyName)] IRef <Session> sessionRef,
     [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe,
     Api.Azure.AzureApplication application,
     ContentTypeResponse <Session> onUpdated,
     NotFoundResponse onNotFound,
     ForbiddenResponse forbidden,
     ConfigurationFailureResponse onConfigurationFailure,
     GeneralConflictResponse onFailure)
 {
     return(sessionRef.StorageUpdateAsync(
                (sessionStorage, saveSessionAsync) =>
     {
         return Security.AppSettings.TokenScope.ConfigurationUri(
             scope =>
         {
             return Security.SessionServer.Configuration.AppSettings.TokenExpirationInMinutes.ConfigurationDouble(
                 async(tokenExpirationInMinutes) =>
             {
                 return await await GetClaimsAsync(application, authorizationRefMaybe,
                                                   async(claims, accountIdMaybe, authorized) =>
                 {
                     sessionStorage.authorization = authorizationRefMaybe;
                     sessionStorage.authorized = authorized;
                     sessionStorage.account = accountIdMaybe;
                     return await BlackBarLabs.Security.Tokens.JwtTools.CreateToken(sessionRef.id,
                                                                                    scope, TimeSpan.FromMinutes(tokenExpirationInMinutes), claims,
                                                                                    async(tokenNew) =>
                     {
                         sessionStorage.token = tokenNew;
                         await saveSessionAsync(sessionStorage);
                         return onUpdated(sessionStorage);
                     },
                                                                                    (missingConfig) => onConfigurationFailure("Missing", missingConfig).AsTask(),
                                                                                    (configName, issue) => onConfigurationFailure(configName, issue).AsTask());
                 },
                                                   why => onFailure(why).AsTask());
             },
                 why => onConfigurationFailure("Missing", why).AsTask());
         },
             (why) => onConfigurationFailure("Missing", why).AsTask());
     },
                onNotFound: () => onNotFound()));
 }
예제 #11
0
 public static Task <HttpResponseMessage> GetByRequestIdAsync(
     [QueryParameter(Name = SessionIdPropertyName, CheckFileName = true)] IRef <Session> sessionRef,
     [QueryParameter(Name = "request_id")] IRef <Authorization> authorization,
     EastFive.Api.SessionToken security,
     Api.Azure.AzureApplication application, UrlHelper urlHelper,
     ContentTypeResponse <Session> onUpdated,
     NotFoundResponse onNotFound,
     ForbiddenResponse forbidden,
     ConfigurationFailureResponse onConfigurationFailure,
     GeneralConflictResponse onFailure)
 {
     return(UpdateBodyAsync(sessionRef, authorization.Optional(),
                            application,
                            onUpdated,
                            onNotFound,
                            forbidden,
                            onConfigurationFailure,
                            onFailure));
 }
예제 #12
0
        public async static Task <IHttpResponse> CreateAsync(
            [Property(Name = AccountPropertyName)] Guid accountId,
            [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe,
            [Resource] XIntegration integration,
            IAuthApplication application, EastFive.Api.SessionToken security,
            CreatedResponse onCreated,
            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse onForbidden,
            ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist,
            GeneralConflictResponse onFailure)
        {
            if (!await application.CanAdministerCredentialAsync(accountId, security))
            {
                return(onForbidden());
            }

            return(await await authorizationRefMaybe.StorageGetAsync(
                       async authorization =>
            {
                if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization))
                {
                    return onFailure("Authorization is not accessable to this account.");
                }

                return await CreateWithAuthorization(integration, authorization,
                                                     () => onCreated(),
                                                     () => onAlreadyExists(),
                                                     (why) => onFailure(why));
            },
                       async() =>
            {
                if (authorizationRefMaybe.HasValue)
                {
                    return onAuthorizationDoesNotExist();
                }
                return await integration.StorageCreateAsync(
                    (discard) => onCreated(),
                    () => onAlreadyExists());
            }));
        }
예제 #13
0
        public async static Task <IHttpResponse> AuthorizeAsync(
            [QueryParameter(Name = "session")]
            IRef <Session> sessionRef,

            [UpdateId(Name = AuthorizationIdPropertyName)]
            IRef <Authorization> authorizationRef,

            [Property(Name = ParametersPropertyName)]
            IDictionary <string, string> parameters,

            Api.Azure.AzureApplication application,
            IInvokeApplication endpoints,
            IHttpRequest request,
            CreatedBodyResponse <Session> onCreated,
            NotFoundResponse onAuthorizationDoesNotExist,
            ForbiddenResponse onAuthorizationFailed,
            ServiceUnavailableResponse onServiceUnavailable,
            ForbiddenResponse onInvalidMethod,
            GeneralConflictResponse onFailure)
        {
            return(await await authorizationRef.StorageGetAsync(
                       (authorization) =>
            {
                return AuthenticateWithSessionAsync(authorizationRef, sessionRef,
                                                    authorization.Method, parameters,
                                                    application, endpoints, request,
                                                    onAuthorized: (sessionCreated, redirect) =>
                {
                    var response = onCreated(sessionCreated, contentType: "application/json");
                    response.SetLocation(redirect);
                    return response;
                },
                                                    onAuthorizationDoesNotExist: () => onAuthorizationDoesNotExist(),
                                                    onServiceUnavailable: (why) => onServiceUnavailable().AddReason(why),
                                                    onInvalidMethod: (why) => onInvalidMethod().AddReason(why),
                                                    onAuthorizationFailed: why => onAuthorizationFailed().AddReason(why));
            },
                       () => onAuthorizationDoesNotExist().AsTask()));
        }
예제 #14
0
        [Api.HttpPost] //(MatchAllBodyParameters = false)]
        public async static Task <IHttpResponse> CreateAsync(
            [Property(Name = AccountPropertyName)] Guid accountId,
            [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe,
            [Resource] Integration integration,
            Api.Azure.AzureApplication application,
            EastFive.Api.SessionToken security,
            CreatedResponse onCreated,
            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse forbidden,
            ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist,
            GeneralConflictResponse onFailure)
        {
            if (!await application.CanAdministerCredentialAsync(accountId, security))
            {
                return(forbidden());
            }

            return(await await authorizationRefMaybe.StorageGetAsync(
                       authorization =>
            {
                // TODO? This
                // var accountIdDidMatch = await await authorization.ParseCredentailParameters(
                return CreateWithAuthorization(integration, authorization,
                                               accountId,
                                               () => onCreated(),
                                               () => onAlreadyExists(),
                                               (why) => onFailure(why));
            },
                       async() =>
            {
                return await await integration.StorageCreateAsync(
                    discard =>
                {
                    return SaveAccountLookupAsync(accountId, integration,
                                                  () => onCreated());
                },
                    () => onAlreadyExists().AsTask());
            }));
        }
예제 #15
0
        public static async Task <IHttpResponse> DeleteAsync(
            [UpdateId(Name = IntegrationIdPropertyName)] IRef <XIntegration> integrationRef,
            IAuthApplication application, EastFive.Api.SessionToken security,
            NoContentResponse onDeleted,
            NotFoundResponse onNotFound,
            ForbiddenResponse onForbidden)
        {
            var integrationMaybe = await integrationRef.StorageGetAsync(i => i, () => default(XIntegration?));

            if (!integrationMaybe.HasValue)
            {
                return(onNotFound());
            }

            var integration = integrationMaybe.Value;

            if (!await application.CanAdministerCredentialAsync(integration.accountId, security))
            {
                return(onForbidden());
            }

            return(await DeleteInternalAsync(integrationRef, () => onDeleted(), () => onNotFound()));
        }
예제 #16
0
        public async static Task <IHttpResponse> CreateAuthorizedAsync(
            [UpdateId(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef,
            [Property(Name = MethodPropertyName)] IRef <Method> methodRef,
            [Property(Name = ParametersPropertyName)] IDictionary <string, string> parameters,
            [Resource] Authorization authorization,
            Api.Azure.AzureApplication application, IProvideUrl urlHelper,
            IInvokeApplication endpoints,
            IHttpRequest request,
            CreatedResponse onCreated,
            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse onAuthorizationFailed,
            ServiceUnavailableResponse onServericeUnavailable,
            ForbiddenResponse onInvalidMethod)
        {
            authorization.accountIdMaybe = default;
            authorization.authorized     = false;
            return(await await Auth.Method.ById(methodRef, application,
                                                (method) =>
            {
                var paramsUpdated = parameters;
                //.Append(
                //    authorizationRef.id.ToString().PairWithKey("state"))
                //.ToDictionary();

                return Redirection.AuthenticationAsync(
                    method,
                    paramsUpdated,
                    application, request, endpoints, request.RequestUri,
                    authorizationRef.Optional(),
                    (redirect, accountIdMaybe, discardModifier) => onCreated(),
                    () => onAuthorizationFailed().AddReason("Authorization was not found"),     // Bad credentials
                    why => onServericeUnavailable().AddReason(why),
                    why => onAuthorizationFailed().AddReason(why));
            },
                                                () => onInvalidMethod().AddReason("The method was not found.").AsTask()));
        }
예제 #17
0
        public async static Task <IHttpResponse> CreateAsync(
            [Api.Meta.Flows.WorkflowNewId]
            [Property(Name = SessionIdPropertyName)]
            IRef <Session> sessionId,

            [Api.Meta.Flows.WorkflowParameter(Value = "{{XAuthorization}}")]
            [PropertyOptional(Name = AuthorizationPropertyName)]
            IRefOptional <Authorization> authorizationRefMaybe,

            [Resource] Session session,
            IAuthApplication application,

            [Api.Meta.Flows.WorkflowVariable2(Workflows.AuthorizationFlow.Variables.AuthHeaderName, HeaderNamePropertyName)]
            [Api.Meta.Flows.WorkflowVariable(Workflows.AuthorizationFlow.Variables.TokenName, TokenPropertyName)]
            CreatedBodyResponse <Session> onCreated,

            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse forbidden,
            ConfigurationFailureResponse onConfigurationFailure,
            GeneralConflictResponse onFailure)
        {
            session.refreshToken = Security.SecureGuid.Generate().ToString("N");

            return(await Security.AppSettings.TokenScope.ConfigurationUri(
                       scope =>
            {
                return Security.SessionServer.Configuration.AppSettings.TokenExpirationInMinutes.ConfigurationDouble(
                    async(tokenExpirationInMinutes) =>
                {
                    return await await GetClaimsAsync(application, authorizationRefMaybe,
                                                      (claims, accountIdMaybe, authorized) =>
                    {
                        session.account = accountIdMaybe;
                        session.authorized = authorized;
                        return session.StorageCreateAsync(
                            (sessionIdCreated) =>
                        {
                            return Api.Auth.JwtTools.CreateToken(sessionId.id,
                                                                 scope, TimeSpan.FromMinutes(tokenExpirationInMinutes), claims,
                                                                 (tokenNew) =>
                            {
                                session.token = tokenNew;
                                return onCreated(session);
                            },
                                                                 (missingConfig) => onConfigurationFailure("Missing", missingConfig),
                                                                 (configName, issue) => onConfigurationFailure(configName, issue));
                        },
                            () =>
                        {
                            return Api.Auth.JwtTools.CreateToken(sessionId.id,
                                                                 scope, TimeSpan.FromMinutes(tokenExpirationInMinutes), claims,
                                                                 (tokenNew) =>
                            {
                                session.token = tokenNew;
                                return onCreated(session);
                            },
                                                                 (missingConfig) => onConfigurationFailure("Missing", missingConfig),
                                                                 (configName, issue) => onConfigurationFailure(configName, issue));
                            // onAlreadyExists()
                        });
                    },
                                                      (why) => onFailure(why).AsTask());
                },
                    (why) => onConfigurationFailure("Missing", why).AsTask());
            },
                       (why) => onConfigurationFailure("Missing", why).AsTask()));
        }
예제 #18
0
        public async static Task <IHttpResponse> CreateAuthorizedAsync(
            [WorkflowNewId]
            [QueryParameter(Name = "session")]
            IRef <Session> sessionRef,

            [WorkflowParameterFromVariable(
                 Value = Workflows.PasswordLoginCreateAccount.Variables.Authorization)]
            [UpdateId(Name = AuthorizationIdPropertyName)]
            IRef <Authorization> authorizationRef,

            [WorkflowParameter(Value = "80a7de99-1307-9633-a7b8-ed70578ac6ae")]
            [Property(Name = MethodPropertyName)]
            IRef <Method> methodRef,

            [WorkflowObjectParameter(
                 Key0 = "state", Value0 = "{{InternalAuthState}}",
                 Key1 = "token", Value1 = "{{InternalAuthToken}}")]
            [Property(Name = ParametersPropertyName)]
            IDictionary <string, string> parameters,

            Api.Azure.AzureApplication application,
            IInvokeApplication endpoints,
            IHttpRequest request,
            [WorkflowVariable(Workflows.PasswordLoginCreateAccount.Variables.AccountId, PropertyName = Session.AccountPropertyName)]
            CreatedBodyResponse <Session> onCreated,

            AlreadyExistsResponse onAlreadyExists,
            ForbiddenResponse onAuthorizationFailed,
            ServiceUnavailableResponse onServiceUnavailable,
            ForbiddenResponse onInvalidMethod,
            GeneralConflictResponse onFailure)
        {
            return(await AuthenticateWithSessionAsync(authorizationRef, sessionRef,
                                                      methodRef, parameters,
                                                      application, endpoints, request,
                                                      onAuthorized : (sessionCreated, redirect) =>
            {
                var response = onCreated(sessionCreated, contentType: "application/json");
                response.SetLocation(redirect);
                return response;
            },
                                                      onAuthorizationDoesNotExist : () => onAuthorizationFailed()
                                                      .AddReason("Authorization does not exists"),
                                                      onServiceUnavailable : (why) => onServiceUnavailable().AddReason(why),
                                                      onInvalidMethod : (why) => onInvalidMethod().AddReason(why),
                                                      onAuthorizationFailed : why => onAuthorizationFailed().AddReason(why)));

            //return await await Auth.Method.ById(methodRef, application,
            //    async (method) =>
            //    {
            //        var paramsUpdated = parameters
            //            .Append(
            //                authorizationRef.id.ToString().PairWithKey("state"))
            //            .ToDictionary();
            //        //var authorizationRequestManager = application.AuthorizationRequestManager;
            //        return await await Redirection.AuthenticationAsync(
            //                method,
            //                paramsUpdated,
            //                application, request,
            //                endpoints,
            //                request.RequestUri,
            //                authorizationRef.Optional(),
            //            async (redirect, accountIdMaybe, modifier) =>
            //            {
            //                var session = new Session()
            //                {
            //                    sessionId = sessionRef,
            //                    account = accountIdMaybe,
            //                    authorization = authorizationRef.Optional(),
            //                };
            //                var responseCreated = await Session.CreateAsync(sessionRef, authorizationRef.Optional(),
            //                        session,
            //                        application,
            //                    (sessionCreated, contentType) =>
            //                    {
            //                        var response = onCreated(sessionCreated, contentType: contentType);
            //                        response.SetLocation(redirect);
            //                        return response;
            //                    },
            //                    onAlreadyExists,
            //                    onAuthorizationFailed,
            //                    (why1, why2) => onServericeUnavailable(),
            //                    onFailure);
            //                var modifiedResponse = modifier(responseCreated);
            //                return modifiedResponse;
            //            },
            //            () => onAuthorizationFailed()
            //                .AddReason("Authorization was not found")
            //                .AsTask(), // Bad credentials
            //            why => onServericeUnavailable()
            //                .AddReason(why)
            //                .AsTask(),
            //            why => onAuthorizationFailed()
            //                .AddReason(why)
            //                .AsTask());
            //    },
            //    () => onInvalidMethod().AddReason("The method was not found.").AsTask());
        }