-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMyUserNameSecurityTokenManager.cs
More file actions
35 lines (30 loc) · 1.31 KB
/
MyUserNameSecurityTokenManager.cs
File metadata and controls
35 lines (30 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IdentityModel.Selectors;
using System.ServiceModel;
namespace CoreWcf.Samples.TokenProvider
{
public class MyUserNameSecurityTokenManager : ClientCredentialsSecurityTokenManager
{
MyUserNameClientCredentials myUserNameClientCredentials;
private readonly string _userNameTokenType = "http://schemas.microsoft.com/ws/2006/05/identitymodel/tokens/UserName";
public MyUserNameSecurityTokenManager(MyUserNameClientCredentials myUserNameClientCredentials)
: base(myUserNameClientCredentials)
{
this.myUserNameClientCredentials = myUserNameClientCredentials;
}
public override SecurityTokenProvider CreateSecurityTokenProvider(SecurityTokenRequirement tokenRequirement)
{
// if token requirement matches username token return custom username token provider
// otherwise use base implementation
if (tokenRequirement.TokenType == _userNameTokenType)
{
return new MyUserNameTokenProvider();
}
else
{
return base.CreateSecurityTokenProvider(tokenRequirement);
}
}
}
}