Exemplo n.º 1
0
        public async Task <TResult> CreatedAuthenticationLogoutAsync <TResult>(Guid requestId,
                                                                               AzureApplication application,
                                                                               string reason, string method,
                                                                               IProvideAuthorization provider, IDictionary <string, string> extraParams, Uri redirectUrl,
                                                                               Func <Task <TResult> > onContinue,
                                                                               Func <string, TResult> onStop)
        {
            var loggingTask = CredentialProcessDocument.UpdateAsync(requestId,
                                                                    async(doc, saveAsync) =>
            {
                doc.Message  = "LOGOUT";
                doc.Action   = Enum.GetName(typeof(AuthenticationActions), AuthenticationActions.signin);
                doc.Provider = provider.GetType().FullName;
                doc.SetValuesCredential(extraParams);
                doc.RedirectUrl = redirectUrl.IsDefaultOrNull() ? string.Empty : redirectUrl.ToString();
                await saveAsync(doc);
                return(true);
            },
                                                                    application.AzureContext.DataContext.AzureStorageRepository);
            var resp = await onContinue();

            bool b = await loggingTask;

            return(resp);
        }
Exemplo n.º 2
0
 public Task <TResult> CredentialUnmappedAsync <TResult>(Guid requestId,
                                                         AzureApplication application,
                                                         string subject, string method,
                                                         IProvideAuthorization credentialProvider, IDictionary <string, string> extraParams,
                                                         Func <Guid,
                                                               Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                               Func <string, Task <TResult> >,
                                                               Task <Task <TResult> > > createMappingAsync,
                                                         Func <
                                                             Func <Guid,
                                                                   Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                                   Func <string, Task <TResult> >,
                                                                   Task <Task <TResult> > >,
                                                             Task <TResult> > onContinue,
                                                         Func <string, TResult> onStop)
 {
     return(CredentialProcessDocument.UpdateAsync(requestId,
                                                  async(doc, saveAsync) =>
     {
         doc.Message = "CREDENTIAL LOOKUP NOT FOUND";
         doc.Provider = credentialProvider.GetType().FullName;
         doc.SetValuesCredential(extraParams);
         await saveAsync(doc);
         Func <Guid,
               Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
               Func <string, Task <TResult> >,
               Task <Task <TResult> > > createMappingWrappedAsync =
             async(authorizationId, onCreated, onFailure) =>
         {
             doc.AuthorizationId = authorizationId;
             Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > > onCreateWrapped =
                 async(sessionId, token, refreshToken, action, redirectUrl) =>
             {
                 doc.Message = "LOOKUP CREATED";
                 doc.SessionId = sessionId;
                 doc.Token = token;
                 doc.RefreshToken = refreshToken;
                 doc.Action = Enum.GetName(typeof(AuthenticationActions), action);
                 doc.RedirectUrl = redirectUrl.IsDefaultOrNull() ? string.Empty : redirectUrl.ToString();
                 await saveAsync(doc);
                 return await onCreated(sessionId, token, refreshToken, action, redirectUrl);
             };
             Func <string, Task <TResult> > onFailureWrapped =
                 async(why) =>
             {
                 doc.Message = $"LOOKUP CREATION FAILURE:{why}";
                 await saveAsync(doc);
                 return await onFailure(why);
             };
             return await createMappingAsync(authorizationId, onCreateWrapped, onFailureWrapped);
         };
         var resp = await onContinue(createMappingWrappedAsync);
         return resp;
     },
                                                  application.AzureContext.DataContext.AzureStorageRepository));
 }
 public Task <TResult> CredentialUnmappedAsync <TResult>(Guid requestId, AzureApplication application, string subject, string method,
                                                         IProvideAuthorization credentialProvider, IDictionary <string, string> extraParams,
                                                         Func <Guid, Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                               Func <string, Task <TResult> >, Task <Task <TResult> > > createMappingAsync,
                                                         Func <Func <Guid, Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                                     Func <string, Task <TResult> >, Task <Task <TResult> > >, Task <TResult> > onContinue,
                                                         Func <string, TResult> onStop)
 {
     return(onContinue(createMappingAsync));
 }
        public Task <TResult> CreatedAuthenticationLogoutAsync <TResult>(AzureApplication application,
                                                                         string reason, string method,
                                                                         IProvideAuthorization provider, IDictionary <string, string> extraParams, Uri redirectUrl,
                                                                         Func <Task <TResult> > onContinue,
                                                                         Func <string, TResult> onStop)
        {
            //await saveAuthLogAsync(true, $"Logout:{location} -- {reason}", extraParams);
            application.Telemetry.TrackEvent($"ResponseController.ProcessRequestAsync - location: {redirectUrl.AbsolutePath}");

            return(onContinue());
        }
 public async Task <TResult> TokenRedeemedAsync <TResult>(string method, IProvideAuthorization provider,
                                                          string subject, Guid?stateId, Guid?loginId, IDictionary <string, string> extraParamsWithRedemptionParams,
                                                          Func <Guid, Guid, string, string, AuthenticationActions, IProvideAuthorization, IDictionary <string, string>, Uri, TResult> onLogin,
                                                          Func <Uri, string, IProvideAuthorization, IDictionary <string, string>, TResult> onLogout,
                                                          LookupCredentialNotFoundDelegate <TResult> lookupCredentialNotFound,
                                                          Func <string, TResult> onInvalidToken,
                                                          Func <string, TResult> onNotConfigured,
                                                          Func <string, TResult> onFailure,
                                                          TelemetryClient telemetry)
 {
     telemetry.TrackEvent("Sessions.CreateOrUpdateWithAuthenticationAsync:  Authenticated", extraParamsWithRedemptionParams);
     // This is the case where the login process started from an existing authentication resource
     if (stateId.HasValue)
     {
         telemetry.TrackEvent($"Sessions.CreateOrUpdateWithAuthenticationAsync:  StateId: {stateId.Value.ToString()}");
         return(await AuthenticateStateAsync(stateId.Value, loginId, method, subject, extraParamsWithRedemptionParams,
                                             (authorizationId, authenticationId, token, refreshToken, action, extraParamsAuthenticated, redirectUrl) =>
                                             onLogin(authorizationId, authenticationId, token, refreshToken, action, provider, extraParamsAuthenticated, redirectUrl),
                                             (redirectUrl, reason, extraParamsAuthenticated) => onLogout(redirectUrl, reason, provider, extraParamsAuthenticated),
                                             onInvalidToken,
                                             onNotConfigured,
                                             onFailure));
     }
     // This is the case where the login process started from an external system
     telemetry.TrackEvent("StateId not found.  Starting external system login flow.");
     return(await await dataContext.CredentialMappings.LookupCredentialMappingAsync(method, subject, loginId,
                                                                                    (authenticationId) =>
     {
         telemetry.TrackEvent($"Sessions.CreateOrUpdateWithAuthenticationAsync:  Called from external login system.  AuthenticationId: {authenticationId.ToString()}");
         var authorizationId = Guid.NewGuid();
         return this.CreateLoginAsync(authorizationId, authenticationId, method, default(Uri), extraParamsWithRedemptionParams,
                                      (session) => onLogin(authorizationId, authenticationId, session.token, session.refreshToken, AuthenticationActions.signin, provider, session.extraParams,
                                                           default(Uri)),
                                      "Guid not unique for creating authentication started from external system".AsFunctionException <TResult>(),
                                      onFailure);
     },
                                                                                    () => lookupCredentialNotFound(subject, provider, extraParamsWithRedemptionParams,
                                                                                                                   async(authenticationId, onCreatedLogin, onFailureToCreateLogin) =>
     {
         var sessionId = Guid.NewGuid();
         var authorizationId = sessionId;
         return await await dataContext.CredentialMappings.CreateCredentialMappingAsync <Task <TResult> >(
             sessionId, method, subject, authenticationId,
             async() =>
         {
             return await await this.CreateLoginAsync <Task <TResult> >(authorizationId, authenticationId, method, default(Uri), extraParamsWithRedemptionParams,
                                                                        (session) => onCreatedLogin(sessionId, session.token, session.refreshToken, AuthenticationActions.signin, session.redirectUrl),
                                                                        "Guid not unique for creating authentication started from external system".AsFunctionException <Task <TResult> >(),
                                                                        onFailureToCreateLogin.AsAsyncFunc());
         },
             () => "Guid not unique for creating authentication started from external system".AsFunctionException <Task <TResult> >()(),
             () => onFailureToCreateLogin("Token is already in use.").ToTask());
     })));
 }
        public async Task <TResult> CredentialUnmappedAsync <TResult>(AzureApplication application,
                                                                      string subject, string method,
                                                                      IProvideAuthorization credentialProvider, IDictionary <string, string> extraParams,
                                                                      Func <Guid, Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                                            Func <string, Task <TResult> >, Task <Task <TResult> > > createMappingAsync,
                                                                      Func <TResult> onContinue,
                                                                      Func <string, TResult> onStop)
        {
            application.Telemetry.TrackEvent($"ResponseController.ProcessRequestAsync - Token is not connected to a user in this system.");
            //var updatingAuthLogTask = saveAuthLogAsync(true, $"Login:{subject}/{credentialProvider.GetType().FullName}", extraParams);

            return(onContinue());
        }
Exemplo n.º 7
0
 public static async Task <TResult> UnmappedCredentailAsync <TResult>(AzureApplication application,
                                                                      IProvideAuthorization authorizationProvider, string method, string subject, IDictionary <string, string> extraParams,
                                                                      Uri baseUri,
                                                                      Func <Guid,
                                                                            Func <Guid, string, string, AuthenticationActions, Uri, Task <Task <TResult> > >,
                                                                            Func <string, Task <TResult> >, Task <Task <TResult> > > createMappingAsync,
                                                                      Func <Uri, string, TResult> onRedirect,
                                                                      Func <HttpStatusCode, string, string, TResult> onResponse,
                                                                      TelemetryClient telemetry)
 {
     throw new NotImplementedException();
     //return await await application.OnUnmappedUserAsync<Task<TResult>>(method, authorizationProvider, subject, extraParams,
     //    async (authorizationId) =>
     //    {
     //        //await updatingAuthLogTask;
     //        telemetry.TrackEvent($"ResponseController.ProcessRequestAsync - Creating Authentication.");
     //        //updatingAuthLogTask = saveAuthLogAsync(true, $"New user mapping requested:{subject}/{credentialProvider.GetType().FullName}[{authorizationId}]", extraParams);
     //        return await await createMappingAsync(authorizationId,
     //            async (sessionId, jwtToken, refreshToken, action, redirectUrl) =>
     //            {
     //                //await updatingAuthLogTask;
     //                //await saveAuthLogAsync(true, $"New user mapping requested:{subject}/{credentialProvider.GetType().FullName}[{authorizationId}]", extraParams);
     //                telemetry.TrackEvent($"ResponseController.ProcessRequestAsync - Created Authentication.  Creating response.");
     //                var resp = CreateResponse(application, authorizationProvider, method, action,
     //                        sessionId, authorizationId, jwtToken, refreshToken, extraParams,
     //                        baseUri, redirectUrl,
     //                    onRedirect,
     //                    onResponse,
     //                    telemetry);
     //                //await updatingAuthLogTask;
     //                return resp;
     //            },
     //            async (why) =>
     //            {
     //                //await updatingAuthLogTask;
     //                //await saveAuthLogAsync(true, $"Failure to create user mapping requested:{subject}/{credentialProvider.GetType().FullName}[{authorizationId}]: {why}", extraParams);
     //                var message = $"Failure to connect token to a user in this system: {why}";
     //                telemetry.TrackException(new ResponseException(message));
     //                return onResponse(HttpStatusCode.Conflict, message, message);
     //            });
     //    },
     //    () =>
     //    {
     //        var message = "Token is not connected to a user in this system";
     //        telemetry.TrackException(new ResponseException(message));
     //        return onResponse(HttpStatusCode.Conflict, message, message).ToTask();
     //    });
 }
Exemplo n.º 8
0
        //public static async Task<TResult> LegacyAccountMappingAsync<TResult>(Authorization authorization,
        //        Method authenticationMethod, string externalAccountKey,
        //        IDictionary<string, string> extraParams,
        //        IAzureApplication application,
        //        IProvideLogin loginProvider,
        //        Uri baseUri,
        //    Func<Guid, Func<bool, Task<TResult>>, TResult> onLocated,
        //    Func<Guid, TResult> onCreated,
        //    Func<TResult> onSelfServe,
        //    Func<Uri, TResult> onInterupted,
        //    Func<string, TResult> onGeneralFailure,
        //        TelemetryClient telemetry)
        //{
        //    return await await AccountMapping.FindByMethodAndKeyAsync(
        //            authenticationMethod.authenticationId, externalAccountKey,
        //            authorization,
        //            // Found
        //        internalAccountId =>
        //        {
        //            return onLocated(
        //                    internalAccountId,
        //                    (isAccountInvalid) => OnNotFound(isAccountInvalid))
        //                .AsTask();
        //        },
        //        () => OnNotFound(false));

        //    async Task<TResult> OnNotFound(bool isAccountInvalid)
        //    {
        //        return await await UnmappedCredentialAsync(externalAccountKey, extraParams,
        //                    authenticationMethod, authorization,
        //                    loginProvider, application, baseUri,

        //                // Create mapping
        //                (internalAccountId) =>
        //                {
        //                    return AccountMapping.CreateByMethodAndKeyAsync(
        //                            authorization, externalAccountKey, internalAccountId,
        //                        () =>
        //                        {
        //                            return onCreated(internalAccountId);
        //                        },
        //                        () =>
        //                        {
        //                            return onLocated(internalAccountId, default);
        //                        },
        //                            isAccountInvalid);
        //                },

        //                // Allow self serve
        //                () =>
        //                {
        //                    return onSelfServe().AsTask();
        //                },

        //                // Intercept process
        //                (interceptionUrl) =>
        //                {
        //                    return onInterupted(interceptionUrl).AsTask();
        //                },

        //                // Failure
        //                (why) =>
        //                {
        //                    return onGeneralFailure(why).AsTask();
        //                },
        //                telemetry);
        //    }
        //}

        private static Task <TResult> CreateLoginResponseAsync <TResult>(
            Guid?accountId, IDictionary <string, string> extraParams,
            Method method, Authorization authorization,
            IAuthApplication application,
            IHttpRequest request, IInvokeApplication endpoints,
            Uri baseUrl,
            IProvideAuthorization authorizationProvider,
            Func <Uri, Func <IHttpResponse, IHttpResponse>, TResult> onRedirect,
            Func <string, TResult> onBadResponse,
            TelemetryClient telemetry)
        {
            return(application.GetRedirectUriAsync(
                       accountId, extraParams,
                       method, authorization,
                       request, endpoints,
                       baseUrl,
                       authorizationProvider,
                       (redirectUrlSelected, modifier) =>
            {
                telemetry.TrackEvent($"CreateResponse - redirectUrlSelected1: {redirectUrlSelected.AbsolutePath}");
                telemetry.TrackEvent($"CreateResponse - redirectUrlSelected2: {redirectUrlSelected.AbsoluteUri}");
                return onRedirect(redirectUrlSelected, modifier);
            },
                       (paramName, why) =>
            {
                var message = $"Invalid parameter while completing login: {paramName} - {why}";
                telemetry.TrackException(new ResponseException(message));
                return onBadResponse(message);
            },
                       () =>
            {
                var message = $"Invalid account while completing login";
                telemetry.TrackException(new ResponseException(message));
                return onBadResponse(message);
            },
                       (why) =>
            {
                var message = $"General failure while completing login: {why}";
                telemetry.TrackException(new ResponseException(message));
                return onBadResponse(message);
            }));
        }
Exemplo n.º 9
0
 public virtual async Task <TResult> OnUnmappedUserAsync <TResult>(
     string subject, IDictionary <string, string> extraParameters,
     EastFive.Azure.Auth.Method authentication, EastFive.Azure.Auth.Authorization authorization,
     IProvideAuthorization authorizationProvider, Uri baseUri,
     Func <Guid, TResult> onCreatedMapping,
     Func <TResult> onAllowSelfServeAccounts,
     Func <Uri, TResult> onInterceptProcess,
     Func <TResult> onNoChange)
 {
     if (authorizationProvider is Credentials.IProvideAccountInformation)
     {
         var accountInfoProvider = authorizationProvider as Credentials.IProvideAccountInformation;
         return(await accountInfoProvider
                .CreateAccount(subject, extraParameters,
                               authentication, authorization, baseUri,
                               this,
                               onCreatedMapping,
                               onAllowSelfServeAccounts,
                               onInterceptProcess,
                               onNoChange));
     }
     return(onNoChange());
 }
 private static Task <TResult> UnmappedCredentialAsync <TResult>(
     string subject, IDictionary <string, string> extraParams,
     EastFive.Azure.Auth.Method authentication, Authorization authorization,
     IProvideAuthorization authorizationProvider,
     AzureApplication application,
     Uri baseUri,
     Func <Guid, TResult> createMapping,
     Func <TResult> onAllowSelfServe,
     Func <Uri, TResult> onInterceptProcess,
     Func <string, TResult> onFailure,
     TelemetryClient telemetry)
 {
     return(application.OnUnmappedUserAsync(subject, extraParams,
                                            authentication, authorization, authorizationProvider, baseUri,
                                            (accountId) => createMapping(accountId),
                                            () => onAllowSelfServe(),
                                            (callback) => onInterceptProcess(callback),
                                            () =>
     {
         var message = "Token is not connected to a user in this system";
         telemetry.TrackException(new ResponseException(message));
         return onFailure(message);
     }));
 }
Exemplo n.º 11
0
        public static async Task <TResult> CreateResponse <TResult>(AzureApplication application, IProvideAuthorization authorizationProvider,
                                                                    string method, AuthenticationActions action,
                                                                    Guid sessionId, Guid?authorizationId, string jwtToken, string refreshToken,
                                                                    IDictionary <string, string> extraParams, Uri baseUri, Uri redirectUrl,
                                                                    Func <Uri, string, TResult> onRedirect,
                                                                    Func <HttpStatusCode, string, string, TResult> onResponse,
                                                                    TelemetryClient telemetry)
        {
            throw new NotImplementedException();
            //var redirectResponse = await application.GetRedirectUriAsync(authorizationProvider,
            //        method, action,
            //        sessionId, authorizationId, jwtToken, refreshToken, extraParams,
            //        baseUri,
            //        redirectUrl,
            //    (redirectUrlSelected) =>
            //    {
            //        telemetry.TrackEvent($"CreateResponse - redirectUrlSelected1: {redirectUrlSelected.AbsolutePath}");
            //        telemetry.TrackEvent($"CreateResponse - redirectUrlSelected2: {redirectUrlSelected.AbsoluteUri}");
            //        return onRedirect(redirectUrlSelected, null);
            //    },
            //    (paramName, why) =>
            //    {
            //        var message = $"Invalid parameter while completing login: {paramName} - {why}";
            //        telemetry.TrackException(new ResponseException(message));
            //        return onResponse(HttpStatusCode.BadRequest, message, why);
            //    },
            //    (why) =>
            //    {
            //        var message = $"General failure while completing login: {why}";
            //        telemetry.TrackException(new ResponseException(message));
            //        return onResponse(HttpStatusCode.BadRequest, message, why);
            //    });

            //var msg = redirectResponse;
            //telemetry.TrackEvent($"CreateResponse - {msg}");
            //return redirectResponse;
        }
 public Task <TResult> CreatedAuthenticationLogoutAsync <TResult>(Guid requestId, AzureApplication application, string reason, string method, IProvideAuthorization provider, IDictionary <string, string> extraParams, Uri redirectUrl, Func <Task <TResult> > onContinue, Func <string, TResult> onStop)
 {
     return(onContinue());
 }
 public Task <TResult> CreatedAuthenticationLoginAsync <TResult>(Guid requestId, AzureApplication application, Guid sessionId, Guid authorizationId, string token, string refreshToken, string method, AuthenticationActions action, IProvideAuthorization provider, IDictionary <string, string> extraParams, Uri redirectUrl, Func <Task <TResult> > onContinue, Func <string, TResult> onStop)
 {
     return(onContinue());
 }
        public async Task <TResult> CreatedAuthenticationLoginAsync <TResult>(AzureApplication application,
                                                                              Guid sessionId, Guid authorizationId,
                                                                              string token, string refreshToken,
                                                                              string method, AuthenticationActions action, IProvideAuthorization provider,
                                                                              IDictionary <string, string> extraParams, Uri redirectUrl,
                                                                              Func <Task <TResult> > onContinue,
                                                                              Func <string, TResult> onStop)
        {
            //var updatingAuthLogTask = saveAuthLogAsync(true, $"Login:{authorizationId}/{sessionId}[{action}]", extraParams);
            application.Telemetry.TrackEvent($"ResponseController.ProcessRequestAsync - Created Authentication.  Creating response.");
            var resp = onContinue();

            //await updatingAuthLogTask;
            return(await resp);
        }