public static async Task <TResult> CreateByMethodAndKeyAsync <TResult>(IRef <XIntegration> integrationRef, IRef <Authorization> authorizationRef, IRef <Method> methodRef, Guid accountId, IDictionary <string, string> parameters, Func <XIntegration, Authorization, TResult> onCreated, Func <TResult> onIntegrationAlreadyExists, Func <TResult> onAuthorizationAlreadyExists, Func <string, TResult> onFailure) { var authorization = new Authorization { authorizationRef = authorizationRef, parameters = parameters, Method = methodRef, authorized = true, accountIdMaybe = accountId, }; return(await await authorization.StorageCreateAsync <Authorization, Task <TResult> >( (discardId) => { var integration = new XIntegration { integrationRef = integrationRef, accountId = accountId, authorization = authorizationRef.Optional(), Method = methodRef, }; return CreateWithAuthorization(integration, authorization, () => onCreated(integration, authorization), () => onIntegrationAlreadyExists(), (why) => onFailure(why)); }, () => onAuthorizationAlreadyExists().AsTask())); }
public static async Task <TResult> CreateByMethodAndKeyAsync <TResult>(IRef <Integration> integrationRef, IRef <Authorization> authorizationRef, IRef <Method> methodRef, Guid accountId, IDictionary <string, string> parameters, Func <Integration, Authorization, TResult> onCreated, Func <TResult> onIntegrationAlreadyExists, Func <TResult> onAuthorizationAlreadyExists = default, Func <string, TResult> onFailure = default) { var authorization = new Authorization { authorizationRef = authorizationRef, parameters = parameters, Method = methodRef, authorized = true, accountIdMaybe = accountId, }; return(await await authorization.StorageCreateAsync <Authorization, Task <TResult> >( (discardId) => { var integration = new Integration { integrationRef = integrationRef, accountId = accountId, authorization = authorizationRef.Optional(), Method = methodRef, }; return CreateWithAuthorization(integration, authorization, accountId, () => onCreated(integration, authorization), () => onIntegrationAlreadyExists(), (why) => { if (why.IsDefaultOrNull()) { throw new Exception(why); } return onFailure(why); }); }, () => { if (onAuthorizationAlreadyExists.IsDefaultOrNull()) { throw new Exception("Could not create authorization that already exists."); } return onAuthorizationAlreadyExists().AsTask(); })); }
public static async Task <IHttpResponse> LaunchAsync( [Api.Meta.Flows.WorkflowParameter(Value = "{{AuthenticationMethod}}")] [QueryParameter(Name = "method")] IRef <Method> methodRef, RequestMessage <AccountRequest> api, IHttpRequest request, IAzureApplication application, IProvideUrl urlHelper, [Api.Meta.Flows.WorkflowVariableRedirectUrl( VariableName = Workflows.AuthorizationFlow.Variables.RedirectUrl)] RedirectResponse onLaunched, BadRequestResponse onInvalidMethod) { return(await await Method.ById(methodRef, application, async method => { var authRef = Ref <Authorization> .SecureRef(); var authorization = new Authorization { authorizationRef = authRef, LocationAuthenticationReturn = api // .Where(query => query.authorization == authRef) .HttpAction(ResponseAction) .CompileRequest(request) .RequestUri, Method = methodRef, }; return await await authorization.StorageCreateAsync( async(discard) => { var redir = await method.GetLoginUrlAsync( application, urlHelper, authRef.id); return onLaunched(redir); }); }, () => onInvalidMethod().AsTask())); }
public async static Task <IHttpResponse> CreateAsync( [Api.Meta.Flows.WorkflowNewId] [Property(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef, [Api.Meta.Flows.WorkflowParameter(Value = "{{AuthenticationMethod}}")] [Property(Name = MethodPropertyName)] IRef <Method> method, [Api.Meta.Flows.WorkflowParameter(Value = "http://example.com")] [Property(Name = LocationAuthorizationReturnPropertyName)] Uri locationAuthenticationReturn, [Resource] Authorization authorization, IAuthApplication application, IProvideUrl urlHelper, CreatedBodyResponse <Authorization> onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Method> onAuthenticationDoesNotExist) { authorization.accountIdMaybe = default; authorization.authorized = false; return(await await Auth.Method.ById(method, application, async (method) => { //var authorizationIdSecure = authentication.authenticationId; authorization.LocationAuthentication = await method.GetLoginUrlAsync( application, urlHelper, authorizationRef.id); //throw new ArgumentNullException(); return await authorization.StorageCreateAsync( createdId => onCreated(authorization), () => onAlreadyExists()); }, () => onAuthenticationDoesNotExist().AsTask())); }
public async static Task <HttpResponseMessage> CreateAsync( [Property(Name = AuthorizationIdPropertyName)] Guid authorizationId, [Property(Name = MethodPropertyName)] IRef <Method> method, [Property(Name = LocationAuthorizationReturnPropertyName)] Uri LocationAuthenticationReturn, [Resource] Authorization authorization, Api.Azure.AzureApplication application, UrlHelper urlHelper, CreatedBodyResponse <Authorization> onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Method> onAuthenticationDoesNotExist) { return(await await Auth.Method.ById(method, application, async (authentication) => { //var authorizationIdSecure = authentication.authenticationId; authorization.LocationAuthentication = await authentication.GetLoginUrlAsync( application, urlHelper, authorizationId); throw new NotImplementedException(); return await authorization.StorageCreateAsync( createdId => onCreated(authorization), () => onAlreadyExists()); }, () => onAuthenticationDoesNotExist().AsTask())); }