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); })); }
[Api.HttpPatch] //(MatchAllBodyParameters = false)] public async static Task <HttpResponseMessage> UpdateAsync( [UpdateId(Name = AuthorizationIdPropertyName)] IRef <Authorization> authorizationRef, [Property(Name = LocationLogoutReturnPropertyName)] Uri locationLogoutReturn, EastFive.Api.SessionToken?securityMaybe, NoContentResponse onUpdated, AlreadyExistsResponse onNotFound, UnauthorizedResponse onUnauthorized) { return(await authorizationRef.StorageUpdateAsync( async (authorization, saveAsync) => { if (authorization.deleted.HasValue) { return onNotFound(); } if (authorization.authorized) { authorization.LocationAuthentication = default(Uri); if (!securityMaybe.HasValue) { return onUnauthorized(); } } authorization.LocationLogoutReturn = locationLogoutReturn; await saveAsync(authorization); return onUpdated(); }, () => onNotFound())); }
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 Task <IHttpResponse> CreateAsync( [Property(Name = ProcessStep.IdPropertyName)] Guid processId, [PropertyOptional(Name = ProcessStep.PreviousPropertyName)] Guid?previousStepId, [Property(Name = ProcessStep.ResourcePropertyName)] Guid resourceId, [Property(Name = ProcessStep.StagePropertyName)] Guid processStageId, [Property(Name = ProcessStep.CreatedOnPropertyName)] DateTime createdOn, [PropertyOptional(Name = ProcessStep.ConfirmedByPropertyName)] Guid?confirmedById, [PropertyOptional(Name = ProcessStep.ConfirmedWhenPropertyName)] DateTime?confirmedWhen, [PropertyOptional(Name = ProcessStep.ResourceKeysPropertyName)] string[] resourceKeys, [PropertyOptional(Name = ProcessStep.ResourcesPropertyName)] Guid[] resources, EastFive.Api.Security security, IProvideUrl url, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onStageNotFound, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.Processes.CreateAsync(processId, processStageId, resourceId, createdOn, resourceKeys.NullToEmpty().Zip(resources.NullToEmpty(), (k, id) => k.PairWithValue(id)).ToArray(), previousStepId, confirmedWhen, confirmedById, security, () => onCreated(), () => onAlreadyExists(), () => onStageNotFound(), (why) => onFailure(why))); }
public static async Task <HttpResponseMessage> UpdateAsync( [Property(Name = UserIdentificationPropertyName)] string userIdentification, [Property(Name = PasswordPropertyName)] string password, Api.Azure.AzureApplication application, CreatedResponse onUpdated, AlreadyExistsResponse onUsernameAlreadyTaken, GeneralConflictResponse onInvalidPassword) { if (!password.HasBlackSpace()) { return(onInvalidPassword("Password cannot be empty")); } var accountRef = userIdentification .MD5HashGuid() .AsRef <Account>(); return(await accountRef .StorageCreateOrUpdateAsync( async (created, account, saveAsync) => { if (!created) { return onUsernameAlreadyTaken(); } account.userIdentification = userIdentification; account.password = Account.GeneratePasswordHash(userIdentification, password); await saveAsync(account); return onUpdated(); })); }
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> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom, [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo, [Resource] RepositoryBackup repositoryBackup, AzureApplication application, EastFive.Api.Security security, RequestMessage <TableBackup> requestQuery, IHttpRequest request, EastFive.Analytics.ILogger logger, MultipartAsyncResponse <InvocationMessage> onQueued, AlreadyExistsResponse onAlreadyExists) { CloudStorageAccount account = CloudStorageAccount .Parse(storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); return(await repositoryBackup.StorageCreateAsync( (discard) => { var includedTables = BackupFunction.DiscoverStorageResources() .Where(x => x.message.Any()) .Select(x => x.tableName) .ToArray(); var resourceInfoToProcess = tableClient.GetTables() .Where(table => includedTables.Contains(table.Name, StringComparer.OrdinalIgnoreCase)) .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .Await(readAhead: 10); return onQueued(resourceInfoToProcess); }, () => onAlreadyExists())); }
public static async Task <IHttpResponse> CreateContentAsync( [QueryParameter(CheckFileName = true, Name = ContentIdPropertyName)] Guid contentId, [QueryParameter(Name = ContentPropertyName)] ByteArrayContent content, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists) { var contentType = content.Headers.ContentType.MediaType; var contentBytes = await content.ReadAsByteArrayAsync(); return(await EastFive.Api.Azure.Content.CreateContentAsync(contentId, contentType, contentBytes, () => onCreated(), () => onAlreadyExists())); }
public static async Task <IHttpResponse> CreateContentFormAsync( [Property(Name = ContentIdPropertyName)] Guid contentId, [Property(Name = ContentPropertyName)] byte[] contentBytes, [Header(Content = ContentPropertyName)] System.Net.Http.Headers.MediaTypeHeaderValue mediaHeader, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists) { var contentType = mediaHeader.MediaType; return(await EastFive.Api.Azure.Content.CreateContentAsync(contentId, contentType, contentBytes, () => onCreated(), () => onAlreadyExists())); }
public static Task <IHttpResponse> CreateAsync( [Property(Name = IdPropertyName)] IRef <Claim> claimRef, [Property(Name = ActorPropertyName)] Guid actorId, [Property(Name = TypePropertyName)] string type, [Property(Name = NamePropertyName)] string value, [Resource] Claim claim, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists) { return(claim.StorageCreateAsync( (discard) => onCreated(), onAlreadyExists: () => onAlreadyExists())); }
public static async Task <HttpResponseMessage> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom, [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo, [Resource] RepositoryBackup repositoryBackup, AzureApplication application, RequestMessage <TableBackup> requestQuery, HttpRequestMessage request, EastFive.Analytics.ILogger logger, MultipartResponseAsync <InvocationMessage> onQueued, AlreadyExistsResponse onAlreadyExists) { logger.Trace($"Cleaning backup results"); var repo = AzureTableDriverDynamic.FromStorageString(storageSettingCopyTo); await DeleteAllAsync(GetRepository(storageSettingCopyTo)); CloudStorageAccount account = CloudStorageAccount .Parse(storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); return(await await repositoryBackup.StorageCreateAsync( (discard) => { var resourceInfoToProcess = tableClient .ListTables() .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .AsyncEnumerable(); return onQueued(resourceInfoToProcess); }, () => onAlreadyExists().AsTask())); }
public static async Task <IHttpResponse> CreateAsync( [Resource] Client client, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, GeneralConflictResponse onFailure) { return(await client .StorageCreateAsync( (discard) => { return onCreated(); }, () => onAlreadyExists())); }
[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 Task <HttpResponseMessage> CreateAsync( [Property(Name = Resources.ProcessStage.IdPropertyName)] Guid processStageId, [Property(Name = Resources.ProcessStage.OwnerPropertyName)] Guid ownerId, [Property(Name = Resources.ProcessStage.TypePropertyName)] Guid processStageTypeId, [PropertyOptional(Name = Resources.ProcessStage.TitlePropertyName)] string title, [PropertyOptional(Name = Resources.ProcessStage.ViewablePropertyName)] Guid [] viewableIds, [PropertyOptional(Name = Resources.ProcessStage.CompletablePropertyName)] Guid [] completableIds, [PropertyOptional(Name = Resources.ProcessStage.EditablePropertyName)] Guid [] editableIds, [PropertyOptional(Name = Resources.ProcessStage.ConfirmablePropertyName)] Resources.ProcessStage.ConfirmableResource [] confirmables, EastFive.Api.Security security, EastFive.Api.Azure.AzureApplication application, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStageType> onTypeDoesNotExist, ReferencedDocumentDoesNotExistsResponse <Resources.ProcessStage> onConfirmationStageDoesNotExist, ReferencedDocumentDoesNotExistsResponse <BlackBarLabs.Api.ResourceBase> onActorDoesNotExists, UnauthorizedResponse onUnauthorized, GeneralConflictResponse onFailure) { return(EastFive.Azure.ProcessStages.CreateAsync(processStageId, ownerId, processStageTypeId, title, viewableIds, editableIds, completableIds, confirmables .Select( confirmable => confirmable.ProcessStageNext.ToGuid().Value .PairWithKey( confirmable.Positions .Select(position => position.ToGuid().Value) .ToArray())) .ToArray(), security, () => onCreated(), () => onAlreadyExists(), () => onTypeDoesNotExist(), (missingStageId) => onConfirmationStageDoesNotExist(), () => onActorDoesNotExists(), (why) => onFailure(why))); }
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> UpdateAsync( [WorkflowVariable( Workflows.PasswordLoginCreateAccount.Variables.UserId, UserIdentificationPropertyName)] [WorkflowParameter(Value = "{{$randomUserName}}")] [Property(Name = UserIdentificationPropertyName)] string userIdentification, [WorkflowVariable( Workflows.PasswordLoginCreateAccount.Variables.Password, PasswordPropertyName)] [WorkflowParameter(Value = "{{$randomPassword}}")] [Property(Name = PasswordPropertyName)] string password, CreatedResponse onCreated, AlreadyExistsResponse onUsernameAlreadyTaken, GeneralConflictResponse onInvalidPassword) { if (!password.HasBlackSpace()) { return(onInvalidPassword("Password cannot be empty")); } var accountRef = userIdentification .MD5HashGuid() .AsRef <Account>(); return(await accountRef .StorageCreateOrUpdateAsync( async (created, account, saveAsync) => { if (!created) { return onUsernameAlreadyTaken(); } account.userIdentification = userIdentification; account.password = Account.GeneratePasswordHash(userIdentification, password); await saveAsync(account); return onCreated(); })); }
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> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe, [Resource] XIntegration integration, IAuthApplication application, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onForbidden()); } return(await await authorizationRefMaybe.StorageGetAsync( async authorization => { if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization)) { return onFailure("Authorization is not accessable to this account."); } return await CreateWithAuthorization(integration, authorization, () => onCreated(), () => onAlreadyExists(), (why) => onFailure(why)); }, async() => { if (authorizationRefMaybe.HasValue) { return onAuthorizationDoesNotExist(); } return await integration.StorageCreateAsync( (discard) => onCreated(), () => onAlreadyExists()); })); }
[Api.HttpPost] //(MatchAllBodyParameters = false)] public async static Task <IHttpResponse> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe, [Resource] Integration integration, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ForbiddenResponse forbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthenticationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(forbidden()); } return(await await authorizationRefMaybe.StorageGetAsync( authorization => { // TODO? This // var accountIdDidMatch = await await authorization.ParseCredentailParameters( return CreateWithAuthorization(integration, authorization, accountId, () => onCreated(), () => onAlreadyExists(), (why) => onFailure(why)); }, async() => { return await await integration.StorageCreateAsync( discard => { return SaveAccountLookupAsync(accountId, integration, () => onCreated()); }, () => onAlreadyExists().AsTask()); })); }
public static Task <HttpResponseMessage> CreatePasswordCredentialAsync( [Property(Name = IdPropertyName)] Guid credentialId, [Property(Name = ActorPropertyName)] Guid actorId, [PropertyOptional(Name = DisplayNamePropertyName)] string displayName, [PropertyOptional(Name = UserIdPropertyName)] string userId, [PropertyOptional(Name = TokenPropertyName)] string token, [PropertyOptional(Name = IsEmailPropertyName)] bool isEmail, [PropertyOptional(Name = ForceChangePropertyName)] bool forceChange, [PropertyOptional(Name = LastEmailSentPropertyName)] DateTime?lastEmailSent, Context context, AzureApplication application, UrlHelper url, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, GeneralConflictResponse onUsernameAlreadyInUse, GeneralConflictResponse onInsufficentPassword, GeneralConflictResponse onUsernameAlreadyMappedToActor, UnauthorizedResponse onUnauthorized, ServiceUnavailableResponse onServiceUnavailable, GeneralConflictResponse onFailure) { var callbackUrl = url.GetLocation <EastFive.Api.Azure.Credentials.Controllers.OpenIdResponseController>(); return(context.PasswordCredentials.CreatePasswordCredentialsAsync( credentialId, actorId, displayName, userId, isEmail, token, forceChange, lastEmailSent, callbackUrl, security, application, () => onCreated(), () => onAlreadyExists(), (actorUsingId) => onUsernameAlreadyInUse($"Username already in use with Actor:{actorUsingId}"), () => onInsufficentPassword($"Password is insufficient."), () => onUsernameAlreadyMappedToActor($"Relationship already exists"), () => onUsernameAlreadyMappedToActor($"Login is already in use"), () => onUnauthorized(), () => onServiceUnavailable(), (why) => onFailure(why))); }
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())); }
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> 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 static Task <IHttpResponse> CreateAsync( [EastFive.Api.Meta.Flows.WorkflowNewId] [WorkflowVariable(Workflows.MonitoringFlow.Variables.CreatedNotification, IdPropertyName)] [UpdateId] IRef <TeamsNotification> teamsNotificationRef, [PropertyOptional(Name = RouteFiltersPropertyName)] [WorkflowArrayObjectParameter(Value0 = "/api/*")] string routeFilters, [PropertyOptional(Name = CollectionPropertyName)] [WorkflowParameter(Value = "Collection1", Disabled = true)] string collection, [Resource] TeamsNotification storyBoard, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, UnauthorizedResponse onUnauthorized) { return(storyBoard.HttpPostAsync( onCreated, onAlreadyExists)); }
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())); }
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()); }