Where is IApplicationBuilder.UseJwtBearerAuthentication extension in ASP.net 5? - asp.net-web-api

I've seen examples that that indicate IApplicationBuilder has an extension method .UseJwtBearerAuthentication(Action<?> options).
This SO question and AspNet.Security.OpenIdConnect.Server
sample server startup file seem to say that there is such an extension. On the OpenIdConnect, I looked at the extensions folder and I don't see an extension named UseJwtBearerAuthentication. Even this blog says that it's supposed to be included with ASP.net 5. I also tried adding Microsoft.AspNet.Security.OAuthBearer, 1.0.0-beta3 to my project.json and reference it in Startup.cs. No help.
The only thing I have different is that I'm using -beta7, but I don't think that should matter.

It depends on your runtime version. In beta7 the package is called Microsoft.AspNet.Authentication.OAuthBearer, while in beta 8 the package is renamed to Microsoft.AspNet.Authentication.JwtBearer.
Since you are using beta7, add this to your project.json:
"Microsoft.AspNet.Authentication.OAuthBearer": "1.0.0-beta7"
Pro-tip: never mix beta versions like beta3 security packages and beta7 MVC packages.

In RC2, there are
Microsoft.AspNetCore.Authentication.JwtBearer
Microsoft.AspNetCore.Authentication.OAuth

Related

Sitecore 8.1: Glass.Mapper & Razor

Running a new site on Sitecore 8.1 - installed and setup Glass.Mapper but I cannot use calls such as #RenderImage - it's complaining that i'm missing the reference to Glass.Mapper.Sc.Mvc, which I have already.
The following are the Nuget modules installed for Glass.Mapper:
BoC.Glass.Mapper
BoC.Glass.Mapper.Sc
BoC.Glass.Mapper.Sc.CastleWindsor
Castle Windsor
Castle.Core
Glass.Mapper.Sc
I have it installed on another instance of Sitecore (7.5) - an older version of Glass.Mapper, but I've noticed that the Nuget packages do not exist anymore.
Any ideas?
Thanks!
Dan
BoC.Glass.Mapper is a fork of Glass Mapper, and I believe it has not been updated to V4. Remove it (and any configs that it added or deployed) and start again I say. Just add the Glass.Mapper.Sc nuget package will add in the correct dependencies and is compatible with Sitecore 8.1.
Just to be doubly sure, this is the correct version: https://www.nuget.org/packages/Glass.Mapper.Sc/
Make sure you have Sitecore.Kernel and System.Web.Mvc referenced in your project since there is a post-install step in the nuget package that adds the correct versions of Glass dlls to your project.
To make things simpler V4 uses a Powershell script to decided which
references to add to your project, it checks both the Sitecore.Kernel
version and the System.Web.Mvc version and then installs the
appropriate Glass.Mapper.Sc and Glass.Mapper.Sc.Mvc assembly.
With regards to #RenderImage, either inherit your view from GlassView<> or better to use the extension methods, e.g. #Html.Glass().RenderImage().
More info here: http://glass.lu/Blog/GlassV4

ASP .NET 5 WEB API creating help page

I just got started working on ASP.NET 5. I want to have a help page for my methods, I have seen few examples for creating help pages but most of them are MVC specific. I have gone through Microsoft.AspNet.WebApi.HelpPage package, it creates an Area for help page but I am not using MVC pattern.
Any suggestions how can I create help page other than this area approach?
I would suggest looking at Swagger and SwaggerUI. Swagger is an open standard, using JSON to document an API, used by the likes of PayPal and Microsoft (check out Logic apps in the azure portal).
There are some open source implementations for .Net (both of which I have used), which will self document your API, just by adding the NuGet packages to your project and a little bit of configuration:
https://github.com/domaindrivendev/Swashbuckle
https://github.com/domaindrivendev/Ahoy
Swashbuckle is the original project and Ahoy is the new version targeting ASPNET5. When downloading the package from NuGet you will still get Swashbuckle, just make sure you tick "include pre-release", and if you need any documentation look at the original GitHub project.
SwaggerUI (which is also included in Swashbuckle) adds an interface which you can use to navigate and test your API, by default this is available from "/swagger/ui" when your project is running.
Here is a sample repo in GitHub I put together showing how it can be used: https://github.com/mattridgway/ASPNET5-SwaggerUI

Using System.Web.Http on mac os x

I'm new to mac but not .Net. I'm playing around with Visual Studio Code. I installed Brew and used it to get yo, grunt-cli, generator-aspnet, dnvm, and everything the tutorials say to get. I created a project scaffold with yo and the first thing I want to do is add a Controller that inherits from ApiController but I can't seem to find a way to "Add a reference" like I would in Visual Studio proper.
It looks like I should open project.json and add something like this:
"System.Web.Http": "<some version number>"
under dependencies. I don't know what version number to use, so I tried "latest" but anytime I run dnu update it says System.Web.Http can't be found.
Where can I find information about adding references to Visual Studio Code? How to reference particular DLLs (specifically System.Web.Http for me) and what versions to reference?
The answer to your question has several parts.
ApiController
First of all, ASP.NET MVC 6 unifies WebAPI and MVC 5 controllers into one. You can still use ApiController if you want to, but you will need Microsoft.AspNet.Mvc.WebApiCompatShim.
There is no System.Web.Net
Second, Matt DeKrey is correct. System.Web.Http is not a .NET core library. Depending on what you are trying to do, you may be looking for System.Web.Http.Common.
Finding package version
When using VS Code, you should be seeing autocomplete that will recommend version numbers for you. In this case you could use:
"System.Web.Http.Common": "4.0.20216.16343"

Nuget versioning for MVC3 -> 4 extension library: to hide or not to hide previous versions?

I have an extension package on our corporate nuget server for Asp.Net MVC 3 - let's say the package ID is currently Acme.Mvc and it's version is 2.x.
I've now branched that project and going to put a pre-release version of the same package targetted at MVC 4 Beta. Now, logically this is now version 3.x of the library; however, as soon as I release it (once it's no longer pre-release), the 2.x will no longer appear in VS' UI; which will potentially lead to other developers adding it to their MVC 3 projects; and deny them easy access to any future upgrades to the older v2.x library without using the console).
In a couple of other cases, I've changed the package id to include a version i.e. Acme.Mvc.3 so the new and old can sit side by side. Only problem with that is that it's then possible for someone to try and include both! There's also the slightly pedantic issue that to call that v3.x is not necessarily correct; because it's a new package.
Also, I really need to be able to maintain both streams. I can rely on Binding Redirects in MVC 4 sites that still reference the version of the library that targets MVC 3; since none of my extensions rely on stuff that's gone.
When I look at the public nuget feeds; I rarely ever see this practise of sticking a major version in the package ID, but is there really any alternative?
There are many existing packages that uses the MVC version as part of their naming convention to differentiate between supported versions :
WindowsAzure.WebRole.MVC3
Unity.Mvc3
Spark.Web.Mvc2
Spark.Web.Mvc3
...
"Only problem with that is that it's then possible for someone to try and include both!"
I wouldn't bother trying to block this case, it would seem obvious by the name of the package that both are not meant to be side-by-side.

Where can I get the latest Microsoft.Exchange.WebServices.DLL?

I'm trying to use the latest Exchange Web Services DLL, however when I search my hard drive I see many versions of Microsoft.Exchange.WebServices.DLL, the most recent being version 14.0.650.7 with a date of 1/24/12.
I want to rebuild my machine but can't find an official place to get this DLL. I attempted to download the latest SDK I don't see any DLL to use, nor is there any CHM for me to use.
Where can I get the latest version of Microsoft.Exchange.WebServices.DLL?
Current version of the EWS Managed API is 1.2. It seems that Microsoft sometimes forgets to update links to the newest download which makes it hard to find out what the newest version is but I usually go to www.microsoft.com/downloads and search for "Exchange Web Services Managed API" whenever I need a fresh download.
UPDATE:
EWS is on NuGet:
http://www.nuget.org/packages?q=EWS
This is an old question, and the two answers by the OP and #JakobChristensen do answer the question. I'll just mention that I'm finding the situation fairly confusing.
I recently (manually, not via NuGet) downloaded the current NuGet version, which they currently call "2.2.0".
https://www.nuget.org/packages/Microsoft.Exchange.WebServices/
But the internal file/product version on the .dll is 15.00.0913.015.
According to this page
https://msdn.microsoft.com/en-us/library/office/dn528373(v=exchg.150).aspx
the file should be placed here:
C:\Program Files\Microsoft\Exchange\Web Services\2.0\
So that's where I placed it. Later, when playing around with a Microsoft sample program I noted that it did indeed reference the file at that location.
But another Microsoft sample program referenced the file in the GAC!
C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Exchange.WebServices\15.0.0.0__31bf3856ad364e35\Microsoft.Exchange.WebServices.dll
This version had file/product version 15.00.0847.030.
I'm not sure how that file got there, probably part of a Visual Studio installation.
There's also something called EWSCore, which is apparently a forked version of the official EWS with some bug fixes.
https://www.nuget.org/packages/EWSCore/
My current decision is that I'll consider the official NuGet version to be the version I'll standardize on, and manually download it to my development PC and my build PC and place it here:
C:\Program Files\Microsoft\Exchange\Web Services\2.0\
Options
If you use .net framework, there is a nuget package "Microsoft.Exchange.WebServices 2.2.0" here https://www.nuget.org/packages/Microsoft.Exchange.WebServices
If you use .netstandard/.net5+, you need to go the Github open source project "OfficeDev /
ews-managed-api" here https://github.com/OfficeDev/ews-managed-api , and there you download the code, and compile it. However, this project is targeting .net3.5. So, you need to convert/upgrade it to .netstandard/.net5+ manually and compile it for your self.
!! Update !!: I took the version as of date of this post from GitHub. Replaced Old Style project with SDK project. Target framework set to netstandard2.0. Added packages System.DirectoryServicesandSystem.Security.Cryptography.Xml. In files, I had to remove few namespaces that not compatible, but were not used. Removed AsImageinPhoto, this is public image retrieving method, not needed - it only converts byte array. And fixed loading issue with Assembly.GetExecutingAssembly().GetTypes();`
Type[] types;
try
{
types = Assembly.GetExecutingAssembly().GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
types = ex.Types.Where(t => t != null).ToArray();
}
I also deleted or excluded from project bunch of files related to documentation, fxcop, and assembly info.
And then it worked for sending emails with different API versions. Reading emails is not tested yet.
There is a third option. Nuget has a package "Microsoft.Exchange.WebServices.NETStandard 2.0.0-beta3" But this is not an official Microsoft code. https://www.nuget.org/packages/Microsoft.Exchange.WebServices.NETStandard/2.0.0-beta3
!! Update !!: Got this version and compared to the original code in option #2. This code has more changes than necessary to convert to .netstandard. It has some async stuff added.

Resources