Example #1
0
        public async ValueTask <HttpResponseMessage> Issuer_UpdateV1(string jwt, IssuerV1 model)
        {
            _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", jwt);

            return(await _http.PutAsync("issuer/v1",
                                        new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json")));
        }
Example #2
0
        public IActionResult UpdateV1([FromBody] IssuerV1 model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var issuer = uow.Issuers.GetAsNoTracking(QueryExpressionFactory.GetQueryExpression <tbl_Issuer>()
                                                     .Where(x => x.Id == model.Id).ToLambda())
                         .SingleOrDefault();

            if (issuer == null)
            {
                ModelState.AddModelError(MessageType.IssuerNotFound.ToString(), $"Issuer:{model.Id}");
                return(NotFound(ModelState));
            }

            if (issuer.IsDeletable &&
                issuer.IsDeletable != model.IsDeletable)
            {
                ModelState.AddModelError(MessageType.IssuerImmutable.ToString(), $"Issuer:{issuer.Id}");
                return(BadRequest(ModelState));
            }

            var result = uow.Issuers.Update(map.Map <tbl_Issuer>(model));

            uow.Commit();

            return(Ok(map.Map <IssuerV1>(result)));
        }
Example #3
0
        public IActionResult CreateV1([FromBody] IssuerV1 model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (uow.Issuers.Get(x => x.Name == model.Name).Any())
            {
                ModelState.AddModelError(MessageType.IssuerAlreadyExists.ToString(), $"Issuer:{model.Name}");
                return(BadRequest(ModelState));
            }

            var issuer = uow.Issuers.Create(map.Map <tbl_Issuer>(model));

            uow.Settings.Create(
                map.Map <tbl_Setting>(new SettingV1()
            {
                IssuerId    = issuer.Id,
                ConfigKey   = SettingsConstants.AccessExpire,
                ConfigValue = 600.ToString(),
                IsDeletable = true,
            }));

            uow.Settings.Create(
                map.Map <tbl_Setting>(new SettingV1()
            {
                IssuerId    = issuer.Id,
                ConfigKey   = SettingsConstants.RefreshExpire,
                ConfigValue = 86400.ToString(),
                IsDeletable = true,
            }));

            uow.Settings.Create(
                map.Map <tbl_Setting>(new SettingV1()
            {
                IssuerId    = issuer.Id,
                ConfigKey   = SettingsConstants.TotpExpire,
                ConfigValue = 600.ToString(),
                IsDeletable = true,
            }));

            uow.Settings.Create(
                map.Map <tbl_Setting>(new SettingV1()
            {
                IssuerId    = issuer.Id,
                ConfigKey   = SettingsConstants.PollingMax,
                ConfigValue = 10.ToString(),
                IsDeletable = true,
            }));

            uow.Commit();

            return(Ok(map.Map <IssuerV1>(issuer)));
        }
Example #4
0
        public async ValueTask <IssuerV1> Issuer_UpdateV1(IssuerV1 model)
        {
            var response = await Endpoints.Issuer_UpdateV1(Grant.AccessToken.RawData, model);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadAsAsync <IssuerV1>().ConfigureAwait(false));
            }

            throw new HttpRequestException(response.RequestMessage.ToString(),
                                           new Exception(response.ToString()));
        }
Example #5
0
        public static string ImplicitGrant(IssuerV1 issuer, AudienceV1 audience, UserV1 user, Uri link)
        {
            /*
             * use http://rendera.herokuapp.com/ to test template before format...
             * use https://www.buildmystring.com to format template into string that compiles...
             */

            return("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">" +
                   "<html xmlns=\"http://www.w3.org/1999/xhtml\">" +
                   "  <head>" +
                   "    <!--[if !mso]><!-- -->" +
                   "    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" +
                   "    <style>" +
                   "      @font-face { font-family: Open Sans; src: url('http://fonts.googleapis.com/css?f= amily=Open+Sans'); }" +
                   "    </style>" +
                   "    <!--<![endif]-->" +
                   "    <style>" +
                   "      table { color: inherit; }" +
                   "    </style>" +
                   "  </head>" +
                   "  <body style=\"font-size: 31px; font-family: 'Open Sans', 'Helvetica Neue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color:=#404040; padding: 0; width: 100% !important; -webkit-text-size-adjust: 100%; font-weight: 300 !important; margin: 0; -ms-text-size-adjust: 100%;\" marginheight=\"0\" marginwidth=\"0\" id=\"dbx-email-body\">" +
                   "    <div style=\"max-width: 600px !important; padding: 4px;\">" +
                   "      <table cellpadding=\"0\" cellspacing=\"0\" style=\"padding: 0 45px; width: 100% !important; padding-top: 45px;border: 1px solid #F0F0F0; background-color: #FFFFFF;\" border=\"0\" align=\"center\">" +
                   "        <tr>" +
                   "          <td align=\"center\">" +
                   "            <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" +
                   "              <tr style=\"font-size: 16px; font-weight: 300; color: #404040; font-family: 'Open Sans', 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; line-height: 26px; text-align: left;\">" +
                   "                <td>" +
                   "                  <br>" +
                   "                  <br>Hi " + string.Format("{0} {1}", user.FirstName, user.LastName) + "." +
                   "                  <br>" +
                   "                  <br>The link will log you into the application named " + audience.Name + " automatically." +
                   "                  <br>" +
                   "                  <br><a style=\"border-radius: 4px; font-size: 15px; color: white; text-decoration: none; padding: 14px 7px 14px 7px; width: 210px; max-width: 210px; font-family: 'Open Sans', 'Helvetica Neue', Arial; margin: 0; display: block; background-color:#007ee6; text-align: center;\" href=" + link.AbsoluteUri + ">Login now</a>" +
                   "                  <br>" +
                   "                </td>" +
                   "              <tr>" +
                   "              <tr>" +
                   "                <td height=\"40\"></td>" +
                   "              </tr>" +
                   "            </table>" +
                   "          </td>" +
                   "        </tr>" +
                   "      </table>" +
                   "    </div>" +
                   "  </body>" +
                   "</html>");
        }