0

I am trying to set up a the JWT handler package that can be found on this link: https://msdn.microsoft.com/en-us/library/dn205065(v=vs.110).aspx.

Using several examples online I came accross this piece of code to try and validate a JWT message:

 var validationParameters = new TokenValidationParameters()
                {
                    AllowedAudience = "http://www.example.com",
                    SigningToken = new UserNameSecurityToken(username, password),
                    ValidIssuer = "self"
                };

However, I get an error (the exact error is "type or namespace name is not found...) that UserNameSecurityToken is not present within the System.IdentityModel.Tokens namespace, whilst according the msdn entry about that namespace says it should contain that class. https://msdn.microsoft.com/en-us/library/system.identitymodel.tokens(v=vs.100).aspx

Have I overwritten the namespace by installing the JWT package? Or am I misunderstanding what namespaces are?

Don
  • 1,428
  • 3
  • 15
  • 31
  • Do you have the namespace referenced in your `using`s? if not you'll have to call it by `System.IdentityModel.Tokens.UserNameSecurityToken` – Alfie Goodacre Apr 21 '16 at 14:41
  • The TokenValidationParameters is also present in the same namespace without any trouble. (The System.IdentityModel.Tokens namespace was already present in my using section) – Don Apr 21 '16 at 14:43
  • 3
    Are you clear on the differences between *assemblies* and *namespaces*? Because although both TokenValidationParameters and UserNameSecurityToken are in the same namespace, they're provided by two different assemblies. Are you referencing both required assemblies? – Damien_The_Unbeliever Apr 21 '16 at 14:50
  • @Damien_The_Unbeliever is right. Note that type [`UserNameSecurityToken`](https://msdn.microsoft.com/en-us/library/system.identitymodel.tokens.usernamesecuritytoken.aspx) is claimed to be in assembly _System.IdentityModel.dll_ so you probably need a C# project reference to that one. – Jeppe Stig Nielsen Apr 21 '16 at 14:53
  • So does this mean I can't use the content of the JWT package I installed together with the assembly that uses the UserNameSecurityToken? – Don Apr 21 '16 at 14:55
  • 1
    @Don: add a reference to *System.IdentityModel* and everything would be fine – Arturo Menchaca Apr 21 '16 at 15:06
  • I found out just typing "using System.IdentityModel" in Visual Studio is not enough. I had to add the assembly in the references of my project using, as described in this stackoverflow post: http://stackoverflow.com/questions/19797557/add-a-reference-to-the-system-identitymodel-tokens-dll Thanks a lot guys for having this patience with me! – Don Apr 21 '16 at 15:18

1 Answers1

0

I found out just typing "using System.IdentityModel" in Visual Studio is not enough. I had to add the assembly in the references of my project using, as described in this stackoverflow post: Add a reference to the System.IdentityModel.Tokens DLL Thanks a lot guys for having this patience with me!

Community
  • 1
  • 1
Don
  • 1,428
  • 3
  • 15
  • 31