Ejemplo n.º 1
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,
Ejemplo n.º 2
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()));
        }