Beispiel #1
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()));
        }
Beispiel #2
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()));
        }