public async Task <TResult> CreateLinkAsync <TResult>(Guid authenticationRequestId, Uri callbackLocation, CredentialValidationMethodTypes method, Uri redirectUrl, Guid authenticationId, Guid actorId, System.Security.Claims.Claim[] claims, Func <Session, TResult> onSuccess, Func <TResult> onAlreadyExists, Func <string, TResult> onUnauthorized, Func <TResult> onCredentialSystemNotAvailable, Func <string, TResult> onCredentialSystemNotInitialized, Func <string, TResult> onFailure) { if (!await Library.configurationManager.CanAdministerCredentialAsync(authenticationId, actorId, claims)) { return(onUnauthorized($"Provided token does not permit access to link {authenticationId} to a login")); } return(await context.GetLoginProvider(method, async (provider) => { var sessionId = SecureGuid.Generate(); return await BlackBarLabs.Security.Tokens.JwtTools.CreateToken(sessionId, callbackLocation, TimeSpan.FromMinutes(30), (token) => this.dataContext.AuthenticationRequests.CreateAsync(authenticationRequestId, method, AuthenticationActions.access, authenticationId, token, redirectUrl, redirectUrl, () => onSuccess( new Session() { id = authenticationRequestId, method = method, action = AuthenticationActions.access, loginUrl = provider.GetLoginUrl(authenticationRequestId, callbackLocation), logoutUrl = provider.GetLogoutUrl(authenticationRequestId, callbackLocation), redirectUrl = redirectUrl, authorizationId = authenticationId, token = token, }), onAlreadyExists), why => onFailure(why).ToTask(), (param, why) => onFailure($"Invalid configuration for {param}:{why}").ToTask()); }, onCredentialSystemNotAvailable.AsAsyncFunc(), onCredentialSystemNotInitialized.AsAsyncFunc())); }
public async Task <TResult> CreateLoginAsync <TResult>(Guid authenticationRequestId, CredentialValidationMethodTypes method, Uri redirectUrl, Uri redirectLogoutUrl, Func <Type, Uri> controllerToLocation, Func <Session, TResult> onSuccess, Func <TResult> onAlreadyExists, Func <TResult> onCredentialSystemNotAvailable, Func <string, TResult> onCredentialSystemNotInitialized, Func <string, TResult> onFailure) { return(await context.GetLoginProvider(method, async (provider) => { var callbackLocation = controllerToLocation(provider.CallbackController); var sessionId = SecureGuid.Generate(); var result = await this.dataContext.AuthenticationRequests.CreateAsync(authenticationRequestId, method, AuthenticationActions.signin, redirectUrl, redirectLogoutUrl, () => BlackBarLabs.Security.Tokens.JwtTools.CreateToken(sessionId, callbackLocation, TimeSpan.FromMinutes(30), (token) => { var session = new Session() { id = authenticationRequestId, method = method, action = AuthenticationActions.signin, loginUrl = provider.GetLoginUrl(authenticationRequestId, callbackLocation), logoutUrl = provider.GetLogoutUrl(authenticationRequestId, callbackLocation), redirectUrl = redirectUrl, redirectLogoutUrl = redirectLogoutUrl, token = token, }; return onSuccess(session); }, why => onFailure(why), (param, why) => onFailure($"Invalid configuration for {param}:{why}")), onAlreadyExists); return result; }, onCredentialSystemNotAvailable.AsAsyncFunc(), onCredentialSystemNotInitialized.AsAsyncFunc())); }