TechEdWebApiDemo /TechEdWebApiDemo/App_Start/SecurityConfig.cs

Language C# Lines 99
MD5 Hash 264393f37c4fd1d4974c4265c7b154db
Repository https://github.com/garchibald/TechEdWebApiDemo.git View Raw File
 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TechEdWebApiDemo.App_Start
{
    using System.Web.Http;
    using Resources.Security;
    using Thinktecture.IdentityModel.Tokens.Http;

    public class SecurityConfig
    {
        public static void ConfigureGlobal(HttpConfiguration globalConfig)
        {
            globalConfig.MessageHandlers.Add(
                new AuthenticationHandler(CreateConfiguration()));
            globalConfig.Filters.Add(new SecurityExceptionFilter());

        }

        public static AuthenticationConfiguration CreateConfiguration()
        {
            var config = new AuthenticationConfiguration
                             {
                                 DefaultAuthenticationScheme = "Basic",
                                 EnableSessionToken = true
                             };

            config.SessionToken.EndpointAddress = "/api/token";

            #region Basic Authentication

            config.AddBasicAuthentication((userName, password) => userName == password);

            #endregion


            #region Other Methods

            //#region SimpleWebToken
            //config.AddSimpleWebToken(
            //    "http://identity.thinktecture.com/trust",
            //    Constants.Realm,
            //    Constants.IdSrvSymmetricSigningKey,
            //    AuthenticationOptions.ForAuthorizationHeader("IdSrv"));
            //#endregion

            //#region JsonWebToken
            //config.AddJsonWebToken(
            //    "http://selfissued.test",
            //    Constants.Realm,
            //    Constants.IdSrvSymmetricSigningKey,
            //    AuthenticationOptions.ForAuthorizationHeader("JWT"));
            //#endregion

            //#region IdentityServer SAML
            //var idsrvRegistry = new ConfigurationBasedIssuerNameRegistry();
            //idsrvRegistry.AddTrustedIssuer("A1EED7897E55388FCE60FEF1A1EED81FF1CBAEC6", "Thinktecture IdSrv");

            //var idsrvConfig = new SecurityTokenHandlerConfiguration();
            //idsrvConfig.AudienceRestriction.AllowedAudienceUris.Add(new Uri(Constants.Realm));
            //idsrvConfig.IssuerNameRegistry = idsrvRegistry;
            //idsrvConfig.CertificateValidator = X509CertificateValidator.None;

            //config.AddSaml2(idsrvConfig, AuthenticationOptions.ForAuthorizationHeader("IdSrvSaml"));
            //#endregion

            //#region ACS SWT
            //config.AddSimpleWebToken(
            //    "https://" + Constants.ACS + "/",
            //    Constants.Realm,
            //    Constants.AcsSymmetricSigningKey,
            //    AuthenticationOptions.ForAuthorizationHeader("ACS"));
            //#endregion

            //#region AccessKey
            //var handler = new SimpleSecurityTokenHandler("my access key", token =>
            //    {
            //        if (ObfuscatingComparer.IsEqual(token, "accesskey123"))
            //        {
            //            return new ClaimsIdentity(new Claim[]
            //        {
            //            new Claim("customerid", "123")
            //        }, "Custom");
            //        }

            //        return null;
            //    });

            //config.AddAccessKey(handler, AuthenticationOptions.ForQueryString("key"));
            //#endregion

            #endregion

            return config;
        }
    }
}
Back to Top