Example #1
0
 public static async Task <HttpResponseMessage> CreateResponseAsync(
     [QueryParameter(Name = "login_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                async (document) =>
     {
         var providerKvp = await application.AuthorizationProviders
                           .Where(prov => prov.Value.GetType().FullName == document.Provider)
                           .FirstAsync(
             value => value,
             () => default(KeyValuePair <string, IProvideAuthorization>));
         var provider = providerKvp.Value;
         Enum.TryParse(document.Action, out AuthenticationActions action);
         return await ResponseController.CreateResponse(application, provider, document.Method, action,
                                                        document.SessionId, document.AuthorizationId, document.Token, document.RefreshToken,
                                                        document.GetValuesCredential(), request.RequestUri,
                                                        document.RedirectUrl.IsNullOrWhiteSpace(
                                                            () => null,
                                                            redirUrlString => new Uri(redirUrlString)),
                                                        (redirectUri, message) => redirectResponse(redirectUri),
                                                        (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                        application.Telemetry);
     },
                                                                () => viewResponse("", null).AsTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }
Example #2
0
 public static async Task <HttpResponseMessage> ReplicateLogin(
     [QueryParameter(Name = "credential_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                (document) =>
     {
         return ResponseController.ProcessRequestAsync(application, document.Method, request.RequestUri, document.GetValuesCredential(),
                                                       (redirectUri, message) => redirectResponse(redirectUri),
                                                       (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null));
     },
                                                                () => viewResponse("", null).ToTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }
Example #3
0
 public static async Task <HttpResponseMessage> RedeemAsync(
     [QueryParameter(Name = "redemption_process_id")] Guid credentialProcessId,
     [OptionalQueryParameter(Name = "ApiKeySecurity")] string apiSecurityKey,
     ApiSecurity apiSecurity,
     EastFive.Api.Azure.AzureApplication application, HttpRequestMessage request,
     RedirectResponse redirectResponse,
     ViewStringResponse viewResponse)
 {
     return(await await CredentialProcessDocument.FindByIdAsync(credentialProcessId,
                                                                async (document) =>
     {
         var context = application.AzureContext;
         var responseParameters = document.GetValuesCredential();
         var providerKvp = await application.AuthorizationProviders
                           .Where(prov => prov.Value.GetType().FullName == document.Provider)
                           .FirstAsync(
             value => value,
             () => default(KeyValuePair <string, IProvideAuthorization>));
         var provider = providerKvp.Value;
         return await provider.ParseCredentailParameters(responseParameters,
                                                         async(subject, stateId, loginId) => await await context.Sessions.TokenRedeemedAsync <Task <HttpResponseMessage> >(
                                                             document.Method, provider, subject, stateId, loginId, responseParameters,
                                                             (sessionId, authorizationId, token, refreshToken, actionReturned, providerReturned, extraParams, redirectUrl) =>
         {
             return ResponseController.CreateResponse(application, providerReturned, document.Method, actionReturned, sessionId, authorizationId,
                                                      token, refreshToken, extraParams, request.RequestUri, redirectUrl,
                                                      (redirectUri, message) => redirectResponse(redirectUri),
                                                      (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                      application.Telemetry);
         },
                                                             async(redirectUrl, reason, providerReturned, extraParams) =>
         {
             if (redirectUrl.IsDefaultOrNull())
             {
                 return Web.Configuration.Settings.GetUri(Security.SessionServer.Configuration.AppSettings.LandingPage,
                                                          (redirect) => redirectResponse(redirectUrl),
                                                          (why) => viewResponse($"<html><head><title>{reason}</title></head><body>{why}</body></html>", null));
             }
             if (redirectUrl.Query.IsNullOrWhiteSpace())
             {
                 redirectUrl = redirectUrl.SetQueryParam("cache", Guid.NewGuid().ToString("N"));
             }
             return await redirectResponse(redirectUrl).AsTask();
         },
                                                             (subjectReturned, credentialProvider, extraParams, createMappingAsync) =>
         {
             return ResponseController.UnmappedCredentailAsync(application,
                                                               credentialProvider, document.Method, subjectReturned, extraParams, request.RequestUri,
                                                               createMappingAsync,
                                                               (redirectUri, message) => redirectResponse(redirectUri),
                                                               (code, message, reason) => viewResponse($"<html><head><title>{reason}</title></head><body>{message}</body></html>", null),
                                                               application.Telemetry).ToTask();
         },
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask(),
                                                             application.Telemetry),
                                                         (why) => viewResponse($"<html><head><title>{why}</title></head><body>{why}</body></html>", null).AsTask());
     },
                                                                () => viewResponse("", null).ToTask(),
                                                                BlackBarLabs.Persistence.Azure.StorageTables.AzureStorageRepository.CreateRepository(
                                                                    EastFive.Azure.AppSettings.ASTConnectionStringKey)));
 }