public static Task <IHttpResponse> CreateAsync( [Property(Name = Resources.ProcessStageType.IdPropertyName)] Guid processStageTypeId, [Property(Name = Resources.ProcessStageType.OwnerPropertyName)] Guid ownerId, [Property(Name = Resources.ProcessStageType.GroupPropertyName)] Guid processStageGroupId, [Property(Name = Resources.ProcessStageType.TitlePropertyName)] string title, [Property(Name = Resources.ProcessStageType.ResourceTypePropertyName)] Type resourceType, [Property(Name = Resources.ProcessStageType.ResourceKeysPropertyName)] string[] resourceKeys, [Property(Name = Resources.ProcessStageType.ResourceTypesPropertyName)] Type[] resourceTypes, EastFive.Api.Security security, IHttpRequest request, IProvideUrl url, CreatedResponse onCreated, CreatedBodyResponse <ProcessStageType> onCreatedAndModified, AlreadyExistsResponse onAlreadyExists, AlreadyExistsReferencedResponse onRelationshipAlreadyExists, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { var resourceList = resourceKeys.Zip(resourceTypes, (k, v) => k.PairWithValue(v)).ToArray(); return(ProcessStageTypes.CreateAsync(processStageTypeId, ownerId, processStageGroupId, title, resourceType, resourceList, security, () => onCreated(), () => onAlreadyExists(), () => onReferenceNotFound(), (brokenId) => onReferenceNotFound(), (why) => onFailure(why))); }
public static async Task <IHttpResponse> CreateAccountAsync( [Property(Name = UserNamePropertyName)] string username, [Property(Name = PasswordPropertyName)] string password, IAzureApplication application, IHttpRequest httpRequest, CreatedBodyResponse <Auth.Session> onCreated, AlreadyExistsResponse onUsernameAlreadyTaken, GeneralConflictResponse onInvalidPassword) { if (password.IsNullOrWhiteSpace()) { return(onInvalidPassword("Password cannot be empty")); } return(await Account .GetRef(username) .StorageCreateOrUpdateAsync( async(created, account, saveAsync) => { if (!created) { return onUsernameAlreadyTaken(); } account.userIdentification = username; account.password = Account.GeneratePasswordHash(username, password); await saveAsync(account); var session = await CreateSession(username, application, httpRequest); return onCreated(session); })); }
public async static Task <IHttpResponse> CreateAsync( [Api.Meta.Flows.WorkflowNewId] [Property(Name = IdPropertyName)] IRef <VoucherToken> voucherTokenRef, [Api.Meta.Flows.WorkflowParameter(Value = "{{XAuthorization}}")] [PropertyOptional(Name = AuthIdPropertyName)] Guid?authorizationIdMaybe, [Api.Meta.Flows.WorkflowParameter(Value = "PFJTQ...1ZT4=", Description = "Found in Appsettings as EastFive.Security.Token.Key")] [Property(Name = KeyPropertyName)] string key, [Api.Meta.Flows.WorkflowParameter(Value = "{{$randomDateFuture}}")] [Property(Name = ExpirationPropertyName)] DateTime expiration, [Api.Meta.Flows.WorkflowObjectParameter( Key0 = "http://schemas.microsoft.com/ws/2008/06/identity/claims/role", Value0 = ClaimValues.RoleType + "fb7f557f458c4eadb08652c4a7315fd6", Key1 = ClaimValues.AccountType, Value1 = "{{Account}}")] [Property(Name = ClaimsPropertyName)] Dictionary <string, string> extraClaims, [Resource] VoucherToken voucherToken, [Api.Meta.Flows.WorkflowVariable(Workflows.AuthorizationFlow.Variables.ApiVoucher, TokenPropertyName)] CreatedBodyResponse <VoucherToken> onCreated, AlreadyExistsResponse onAlreadyExists, GeneralConflictResponse onFailure) { return(await VoucherTools.GenerateUrlToken(voucherTokenRef.id, expiration, key, token => { voucherToken.keySignature = key.MD5HashGuid().ToString("N"); voucherToken.token = token; voucherToken.key = default; // Don't save or return the key if (authorizationIdMaybe.HasValue) { voucherToken.claims = voucherToken.claims .NullToEmpty() .Append(Api.AppSettings.ActorIdClaimType.ConfigurationString( (accountIdClaimType) => accountIdClaimType.PairWithValue(authorizationIdMaybe.Value.ToString("N")))) .Distinct(kvp => kvp.Key) .ToDictionary(); } voucherToken.claims = voucherToken.claims .NullToEmpty() .Concat(extraClaims.NullToEmpty()) .Distinct(kvp => kvp.Key) .ToDictionary(); return voucherToken.StorageCreateAsync( createdId => onCreated(voucherToken), () => onAlreadyExists()); }, (why) => onFailure(why).AsTask())); }
public static Task <IHttpResponse> HttpPostAsync <TResource>( this TResource resource, CreatedBodyResponse <TResource> onCreated, AlreadyExistsResponse onAlreadyExists) where TResource : IReferenceable { return(resource.StorageCreateAsync( discard => onCreated(resource), onAlreadyExists: () => onAlreadyExists())); }
public static Task <HttpResponseMessage> CreateConnectorAsync( [Property] Guid id, [Property(Name = EastFive.Api.Resources.Connector.SourcePropertyName)] Guid source, [Property(Name = EastFive.Api.Resources.Connector.DestinationPropertyName)] Guid destination, [Property(Name = EastFive.Api.Resources.Connector.FlowPropertyName)] Connector.SynchronizationMethod Flow, Security security, Context context, HttpRequestMessage request, UrlHelper url, CreatedResponse onCreated, CreatedBodyResponse <Resources.Connection> onCreatedAndModifiedConnection, CreatedBodyResponse <Resources.Connector> onCreatedAndModified, AlreadyExistsResponse onAlreadyExists, AlreadyExistsReferencedResponse onRelationshipAlreadyExists, ReferencedDocumentNotFoundResponse onReferenceNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(Connectors.CreateConnectorAsync(id, source, destination, Flow, security.performingAsActorId, security.claims, () => onCreated(), (connection) => { return request.Headers.Accept .OrderByDescending(accept => accept.Quality.HasValue ? accept.Quality.Value : 1.0) .First( (accept, next) => { if ( accept.MediaType.ToLower() == "x-ordering/connection" || accept.MediaType.ToLower() == "x-ordering/connection+json") { return onCreatedAndModifiedConnection( ConnectionController.GetResource(connection, url), "x-ordering/connection+json"); } if ( accept.MediaType.ToLower() == "x-ordering/connector" || accept.MediaType.ToLower() == "x-ordering/connector+json" || accept.MediaType.ToLower() == "application/json") { return onCreatedAndModified( GetResource(connection.connector, url), "x-ordering/connector+json"); } return next(); }, () => onCreatedAndModified(GetResource(connection.connector, url))); }, () => onAlreadyExists(), (existingConnectorId) => onRelationshipAlreadyExists(existingConnectorId), (brokenId) => onReferenceNotFound(), (why) => onFailure(why))); }
public static async Task <IHttpResponse> AuthenticateAsync( [Property(Name = UserNamePropertyName)] string username, [Property(Name = PasswordPropertyName)] string password, IAzureApplication application, IHttpRequest httpRequest, CreatedBodyResponse <Auth.Session> onSuccess, GeneralConflictResponse onInvalidUserNameOrPassword) { return(await await Authentication.CheckCredentialsAsync(username, password, async account => { var session = await CreateSession(username, application, httpRequest); return onSuccess(session); }, why => onInvalidUserNameOrPassword(why).AsTask())); }
[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())); }
public static async Task <HttpResponseMessage> CreateAsync( [Property(Name = IdPropertyName)] IRef <TableBackup> tableBackupRef, [Property(Name = WhenPropertyName)] DateTime when, [Property(Name = TableNamePropertyName)] string tableName, [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Resource] TableBackup tableBackup, RequestMessage <TableBackup> requestQuery, HttpRequestMessage request, EastFive.Analytics.ILogger logger, CreatedBodyResponse <InvocationMessage> onCreated, AlreadyExistsResponse onAlreadyExists) { return(await await tableBackup.StorageCreateAsync( async (entity) => { var invocationMessage = await requestQuery .ById(tableBackupRef) .HttpPatch(default)
public static async Task <IHttpResponse> CreateAsync( [Property(Name = IdPropertyName)] IRef <TableBackupOperation> tableBackupOperationRef, [Property(Name = WhenPropertyName)] DateTime when, [Property(Name = TableBackupPropertyName)] IRef <TableBackup> tableBackupRef, [Property(Name = OperationSetPropertyName)] string operationSet, [Resource] TableBackupOperation tableBackup, RequestMessage <TableBackupOperation> requestQuery, IHttpRequest request, EastFive.Api.Security security, EastFive.Analytics.ILogger logger, CreatedBodyResponse <InvocationMessage> onCreated, AlreadyExistsResponse onAlreadyExists) { return(await await tableBackup.StorageCreateAsync( async (discard) => { var invocationMessage = await requestQuery .ById(tableBackupOperationRef) .HttpPatch(default)
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())); }
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())); }
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()); }
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())); }