Ejemplo n.º 1
0
        //private static Task<TResult> UnmappedCredentialAsync<TResult>(
        //        string subject, IDictionary<string, string> extraParams,
        //        EastFive.Azure.Auth.Method authentication, Authorization authorization,
        //        IProvideAuthorization authorizationProvider,
        //        IAuthApplication 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);
        //        });
        //}

        public static async Task <TResult> MapAccountAsync <TResult>(Authorization authorization,
                                                                     Guid internalAccountId, string externalAccountKey,
                                                                     IInvokeApplication endpoints,
                                                                     Uri baseUri,
                                                                     AzureApplication application, IHttpRequest request,
                                                                     Func <Uri, TResult> onRedirect,
                                                                     Func <string, TResult> onFailure,
                                                                     TelemetryClient telemetry)
        {
            // applies when intercept process is used
            if (authorization.accountIdMaybe.IsDefault())
            {
                authorization = await authorization.authorizationRef.StorageUpdateAsync(
                    async (a, saveAsync) =>
                {
                    a.accountIdMaybe = internalAccountId;
                    await saveAsync(a);
                    return(a);
                });
            }

            return(await await AccountMapping.CreateByMethodAndKeyAsync(authorization, externalAccountKey,
                                                                        internalAccountId,
                                                                        ProcessAsync,
                                                                        ProcessAsync));

            async Task <TResult> ProcessAsync()
            {
                return(await await Method.ById(authorization.Method, application,
                                               async method =>
                {
                    return await await method.GetLoginProviderAsync(application,
                                                                    (loginProviderMethodName, loginProvider) =>
                    {
                        return CreateLoginResponseAsync(
                            internalAccountId, authorization.parameters,
                            method, authorization,
                            application, request, endpoints, baseUri, loginProvider,
                            (url, modifier) => onRedirect(url),
                            onFailure,
                            telemetry);
                    },
                                                                    () =>
                    {
                        return onFailure("Login provider is no longer supported by the system").AsTask();
                    });
                },
                                               () => onFailure("Method no longer suppored.").AsTask()));
            }
        }
 public static async Task <TResult> MapAccountAsync <TResult>(Authorization authorization,
                                                              Guid internalAccountId, string externalAccountKey,
                                                              Guid requestId,
                                                              Uri baseUri,
                                                              AzureApplication application,
                                                              Func <Uri, TResult> onRedirect,
                                                              Func <string, TResult> onFailure,
                                                              TelemetryClient telemetry)
 {
     return(await await AccountMapping.CreateByMethodAndKeyAsync(authorization, externalAccountKey,
                                                                 internalAccountId,
                                                                 async() =>
     {
         return await await Method.ById(authorization.Method, application,
                                        async method =>
         {
             return await await method.GetLoginProviderAsync(application,
                                                             (loginProviderMethodName, loginProvider) =>
             {
                 return CreateLoginResponseAsync(requestId,
                                                 internalAccountId, authorization.parameters,
                                                 method, authorization,
                                                 baseUri,
                                                 application, loginProvider,
                                                 (url) => onRedirect(url),
                                                 onFailure,
                                                 telemetry);
             },
                                                             () =>
             {
                 return onFailure("Login provider is no longer supported by the system").AsTask();
             });
         },
                                        () => onFailure("Method no longer suppored.").AsTask());
     },
                                                                 (why) => onFailure(why).AsTask()));
 }