usingFunq;usingServiceStack;usingServiceStack.Auth;usingServiceStack.Caching;usingServiceStack.Data;usingServiceStack.OrmLite;usingWebApplication1.ServiceInterface;namespaceWebApplication1{//VS.NET Template Info: https://servicestack.net/vs-templates/EmptyAspNetpublicclassAppHost:AppHostBase{/// <summary>/// Base constructor requires a Name and Assembly where web service implementation is located/// </summary>publicAppHost():base("WebApplication1",typeof(MyServices).Assembly){}/// <summary>/// Application specific configuration/// This method should initialize any IoC resources utilized by your web service classes./// </summary>publicoverridevoidConfigure(Containercontainer){//Store UserAuth in SQL ServervardbFactory=newOrmLiteConnectionFactory("[redacted]",SqlServerDialect.Provider);container.Register<IDbConnectionFactory>(dbFactory);container.Register<IAuthRepository>(c=>newOrmLiteAuthRepository(dbFactory){UseDistinctRoleTables=true});//Create UserAuth RDBMS Tablescontainer.Resolve<IAuthRepository>().InitSchema();//Also store User Sessions in SQL Servercontainer.RegisterAs<OrmLiteCacheClient,ICacheClient>();container.Resolve<ICacheClient>().InitSchema();varprivateKey=RsaUtils.CreatePrivateKeyParams(RsaKeyLengths.Bit2048);varpublicKey=privateKey.ToPublicRsaParameters();varprivateKeyXml=privateKey.ToPrivateKeyXml();varpublicKeyXml=privateKey.ToPublicKeyXml();// just for testing, create a privateKeyXml on every instancePlugins.Add(newAuthFeature(()=>newAuthUserSession(),newIAuthProvider[]{newJwtAuthProvider{HashAlgorithm="RS256",PrivateKeyXml=privateKeyXml},newCredentialsAuthProvider()}));Plugins.Add(newRegistrationFeature());// uncomment to create a first new user//var authRepo = GetAuthRepository();//authRepo.CreateUserAuth(new UserAuth//{// Id = 1,// UserName = "Stefan",// FirstName = "First",// LastName = "Last",// DisplayName = "Display",//}, "p@55word");}}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.