public static Task <HttpResponseMessage> CredentialOptionsAsync(this HttpRequestMessage request)
        {
            var credentialProviders = new Resources.PasswordCredential[]
            {
                new Resources.PasswordCredential
                {
                    UserId = "0123456789",
                    Token  = "ABC.123.MXC",
                },
                new Resources.PasswordCredential
                {
                    //Method = CredentialValidationMethodTypes.OpenIdConnect,
                    //Provider = new Uri("urn:auth.gibbits.nc2media.com/AuthOpenIdConnect/"),
                    UserId = Guid.NewGuid().ToString("N"),
                    Token  = "EDF.123.A3EF",
                },
                new Resources.PasswordCredential
                {
                    //Method = CredentialValidationMethodTypes.Implicit,
                    //Provider = new Uri("http://www.example.com/ImplicitAuth"),
                    UserId = Guid.NewGuid().ToString("N"),
                    Token  = Guid.NewGuid().ToString("N"),
                }
            };
            var response = new BlackBarLabs.Api.Resources.Options()
            {
                Get = credentialProviders,
            };

            var responseMessage = request.CreateResponse(System.Net.HttpStatusCode.OK, response);

            return(responseMessage.ToTask());
        }
 public static async Task <HttpResponseMessage> CreateAsync(this Resources.PasswordCredential credential,
                                                            HttpRequestMessage request, UrlHelper url)
 {
     return(await request.GetActorIdClaimsAsync(ClaimsDefinitions.AccountIdClaimType,
                                                async (performingActorId, claims) =>
     {
         var response = await CreatePasswordCredentialAsync(credential, request, url, performingActorId, claims);
         return response;
     }));
 }
        public static async Task <HttpResponseMessage> PutAsync(this Resources.PasswordCredential credential,
                                                                HttpRequestMessage request, UrlHelper url)
        {
            return(await request.GetActorIdClaimsAsync(ClaimsDefinitions.AccountIdClaimType,
                                                       async (performingActorId, claims) =>
            {
                var callbackUrl = url.GetLocation <Controllers.OpenIdResponseController>();

                var context = request.GetSessionServerContext();
                var creationResults = await context.PasswordCredentials.UpdatePasswordCredentialAsync(credential.Id.UUID,
                                                                                                      credential.Token, credential.ForceChange, credential.LastEmailSent, callbackUrl,
                                                                                                      performingActorId, claims,
                                                                                                      () => request.CreateResponse(HttpStatusCode.NoContent),
                                                                                                      () => request.CreateResponse(HttpStatusCode.NotFound),
                                                                                                      () => request.CreateResponse(HttpStatusCode.Unauthorized),
                                                                                                      () => request.CreateResponse(HttpStatusCode.ServiceUnavailable),
                                                                                                      (why) => request.CreateResponse(HttpStatusCode.Conflict).AddReason($"Update failed:{why}"));
                return creationResults;
            }));
        }
        private static async Task <HttpResponseMessage> CreatePasswordCredentialAsync(Resources.PasswordCredential credential,
                                                                                      HttpRequestMessage request, UrlHelper url,
                                                                                      Guid performingActorId, System.Security.Claims.Claim[] claims)
        {
            var actorId = credential.Actor.ToGuid();

            if (!actorId.HasValue)
            {
                return(request.CreateResponse(HttpStatusCode.Conflict).AddReason("Actor is null"));
            }

            var context     = request.GetSessionServerContext();
            var callbackUrl = url.GetLocation <Controllers.OpenIdResponseController>();

            var creationResults = await context.PasswordCredentials.CreatePasswordCredentialsAsync(
                credential.Id.UUID, actorId.Value,
                credential.DisplayName, credential.UserId, credential.IsEmail, credential.Token, credential.ForceChange,
                credential.LastEmailSent, callbackUrl,
                performingActorId, claims,
                () => request.CreateResponse(HttpStatusCode.Created),
                () => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason($"Credential already exists"),
                (actorUsingId) => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason($"Username already in use with Actor:{actorUsingId}"),
                () => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason($"Password is insufficient."),
                () => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason($"Relationship already exists"),
                () => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason($"Login is already in use"),
                () => request.CreateResponse(HttpStatusCode.Unauthorized),
                () => request.CreateResponse(HttpStatusCode.ServiceUnavailable),
                (why) => request.CreateResponse(HttpStatusCode.Conflict)
                .AddReason(why));

            return(creationResults);
        }