Skip to content

Instantly share code, notes, and snippets.

window.accessToken = null;
window.tokenDefer = $.Deferred();
var adLoginService = (function ($) {
$(document).ready(function () {
console.log("doc ready from AD Login");
window.config = {
clientId: '<clientId of the azure AD app>',
//
// The Client ID is used by the application to uniquely identify itself to Azure AD.
// The Tenant is the name of the Azure AD tenant in which this application is registered.
// The AAD Instance is the instance of Azure, for example public Azure or Azure China.
// The Redirect URI is the URI where Azure AD will return OAuth responses.
// The Authority is the sign-in URL of the tenant.
//
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
--1. get all indexes from current db, place in temp table
select
tablename = object_name(i.id),
tableid = i.id,
indexid = i.indid,
indexname = i.name,
public class ADAuthorizeAttribute : System.Web.Http.AuthorizeAttribute
{
static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance1"];
static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
static string audience = ConfigurationManager.AppSettings["ida:Audience"];
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
static string _issuer = string.Empty;
static List<SecurityToken> _signingTokens = null;
public class ProductController : Controller
{
private ProductService _productService;
// GET: Product
public async Task<ActionResult> Index()
{
this._productService = new ProductService();
public static string GetProps<T>(Expression<Func<T, object>> parameters)
{
StringBuilder requestedParametersString = new StringBuilder();
if (parameters != null && parameters.Body != null)
{
var body = parameters.Body as System.Linq.Expressions.NewExpression;
if (body.Members != null && body.Members.Any())
{
foreach (var member in body.Members)
{
public class ProductService
{
private string BaseUrl { get; set; }
private HttpClient client { get; set; }
public ProductService()
{
client = new HttpClient();
BaseUrl = "http://myproductswebapi.azurewebsites.net/api/products";
// GET: Product
public async Task<ActionResult> Index()
{
this._productService = new ProductService();
var products = await this._productService.GetProducts(x => new { x.Id, x.Name, x.Price });
return View("Products",products);
}
// GET: Product/Details/5
public async Task<ActionResult> Details(int id)
public class ShouldSerializeContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(System.Reflection.MemberInfo member, Newtonsoft.Json.MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
if (property.DeclaringType == typeof(BaseEntity) || property.DeclaringType.BaseType == typeof(BaseEntity))
{
if (property.PropertyName == "serializableProperties")
{
// GET api/products/5
public JsonResult<Product> Get(int id, string fields="")
{
var product = _productsRepository.Find(x => x.Id == id);
product.SetSerializableProperties(fields);
return Json(product, new Newtonsoft.Json.JsonSerializerSettings()
{
ContractResolver = new ShouldSerializeContractResolver()
});
}