Exemplo n.º 1
0
        public static async Task <HttpResponseMessage> UpdateAsync(this Resources.Integration resource,
                                                                   HttpRequestMessage request)
        {
            return(await request.GetActorIdClaimsAsync(
                       async (actingAs, claims) =>
            {
                var context = request.GetSessionServerContext();

                var application = request.GetApplication(
                    app => app as AzureApplication,
                    () => null);

                // Can't update a session that does not exist
                var session = await context.Integrations.UpdateAsync(resource.Id.ToGuid().Value,
                                                                     actingAs, claims, application, resource.Name,
                                                                     resource.UserParameters
                                                                     .ToDictionary(
                                                                         userParam => userParam.Key,
                                                                         userParam => userParam.Value.Value),
                                                                     () => request.CreateResponse(HttpStatusCode.NoContent),
                                                                     (sessionId, authId, token, refreshToken, action, extraParams, redirectUrl) =>
                {
                    resource.AuthorizationId = authId;
                    return request.CreateResponse(HttpStatusCode.Accepted, resource);
                },
                                                                     (logoutRedirect, why, extraParams) => request.CreateRedirectResponse(logoutRedirect).AddReason(why),
                                                                     (why) => request.CreateResponse(HttpStatusCode.NotFound).AddReason(why),
                                                                     () => request.CreateResponse(HttpStatusCode.Conflict).AddReason("User in token is not connected to this system"),
                                                                     (why) => request.CreateResponse(HttpStatusCode.BadGateway).AddReason(why),
                                                                     (why) => request.CreateResponseConfiguration(string.Empty, why),
                                                                     (why) => request.CreateResponseUnexpectedFailure(why));
                return session;
            }));
        }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> CreateAsync(this Resources.Integration authenticationRequest,
                                                                   HttpRequestMessage request, UrlHelper urlHelper)
        {
            var context      = request.GetSessionServerContext();
            var credentialId = authenticationRequest.Id.ToGuid();

            if (!credentialId.HasValue)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest).AddReason("Id must have value"));
            }

            if (authenticationRequest.AuthorizationId.IsDefault())
            {
                return(request.CreateResponseEmptyId(authenticationRequest, ar => ar.AuthorizationId)
                       .AddReason("Authorization Id must have value for integration"));
            }

            return(await request.GetActorIdClaimsAsync(
                       (actorId, claims) =>
                       context.Integrations.CreateLinkAsync(credentialId.Value,
                                                            urlHelper.GetLocation <Controllers.OpenIdResponseController>(),
                                                            authenticationRequest.Method, authenticationRequest.LocationAuthenticationReturn,
                                                            authenticationRequest.AuthorizationId, actorId, claims,
                                                            type => urlHelper.GetLocation(type),
                                                            (authenticationRequestPopulated) =>
            {
                var resource = Convert(authenticationRequestPopulated, urlHelper);
                return request.CreateResponse(HttpStatusCode.Created, resource);
            },
                                                            () => request.CreateAlreadyExistsResponse <Controllers.SessionController>(
                                                                credentialId.Value, urlHelper),
                                                            (why) => request.CreateResponse(HttpStatusCode.Unauthorized).AddReason(why),
                                                            () => request.CreateResponse(HttpStatusCode.BadRequest)
                                                            .AddReason($"Method [{authenticationRequest.Method}] is not enabled for this system"),
                                                            (why) => request.CreateResponse(HttpStatusCode.ServiceUnavailable)
                                                            .AddReason(why),
                                                            (why) => request.CreateResponse(HttpStatusCode.InternalServerError)
                                                            .AddReason(why))));
        }