├── .gitignore
├── .idea
└── .idea.Refresh-Tokens-Demo.dir
│ └── .idea
│ ├── encodings.xml
│ ├── indexLayout.xml
│ ├── misc.xml
│ ├── projectSettingsUpdater.xml
│ ├── vcs.xml
│ └── workspace.xml
├── Features
└── User
│ ├── Auth
│ ├── Allow.cs
│ ├── Login
│ │ ├── Data.cs
│ │ ├── Endpoint.cs
│ │ └── Request.cs
│ ├── MyTokenResponse.cs
│ └── RefreshToken
│ │ ├── Data.cs
│ │ ├── RefreshToken.cs
│ │ └── UserTokenService.cs
│ ├── Profile
│ ├── Data.cs
│ ├── Endpoint.cs
│ ├── Mapper.cs
│ └── Models.cs
│ ├── Signup
│ ├── Data.cs
│ ├── Endpoint.cs
│ ├── Mapper.cs
│ └── Models.cs
│ └── User.cs
├── LICENSE
├── Program.cs
├── Properties
└── launchSettings.json
├── README.md
├── Refresh-Tokens-Demo.csproj
├── appsettings.Development.json
└── appsettings.json
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/indexLayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | EditorConfig
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | 1696760591573
30 |
31 |
32 | 1696760591573
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/projectSettingsUpdater.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/.idea.Refresh-Tokens-Demo.dir/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Refresh-Tokens-Demo.csproj
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
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 |
--------------------------------------------------------------------------------
/Features/User/Auth/Allow.cs:
--------------------------------------------------------------------------------
1 | namespace User.Auth;
2 |
3 | public class Allow : Permissions
4 | {
5 | public const string User_Profile_View = "100";
6 | public const string User_Profile_Edit = "101";
7 | public const string User_Profile_Update = "102";
8 | public const string User_Profile_Delete = "103";
9 | }
--------------------------------------------------------------------------------
/Features/User/Auth/Login/Data.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Entities;
2 |
3 | namespace User.Auth.Login;
4 |
5 | public static class Data
6 | {
7 | public static async Task GetUserID(string email, string password)
8 | {
9 | return await DB.Find()
10 | .Match(u => u.Email == email && u.Password == password) //never store clear text passwords in db
11 | .Project(u => u.ID)
12 | .ExecuteSingleAsync();
13 | }
14 | }
--------------------------------------------------------------------------------
/Features/User/Auth/Login/Endpoint.cs:
--------------------------------------------------------------------------------
1 | using User.Auth.RefreshToken;
2 |
3 | namespace User.Auth.Login;
4 |
5 | public class Endpoint : Endpoint
6 | {
7 | public override void Configure()
8 | {
9 | Post("user/auth/login");
10 | AllowAnonymous();
11 | }
12 |
13 | public override async Task HandleAsync(Request r, CancellationToken c)
14 | {
15 | var userID = await Data.GetUserID(r.Email, r.Password);
16 |
17 | if (userID is null)
18 | ThrowError("Invalid user credentials!");
19 |
20 | Response = await CreateTokenWith(userID, p =>
21 | {
22 | p.Claims.Add(new("UserID", userID));
23 | p.Permissions.AddRange(new Allow().AllCodes());
24 | });
25 | }
26 | }
--------------------------------------------------------------------------------
/Features/User/Auth/Login/Request.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS8618
2 | namespace User.Auth.Login;
3 |
4 | public class Request
5 | {
6 | public string Email { get; set; }
7 | public string Password { get; set; }
8 | }
--------------------------------------------------------------------------------
/Features/User/Auth/MyTokenResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 |
3 | namespace User.Auth
4 | {
5 | public class MyTokenResponse : TokenResponse
6 | {
7 | //ideally should be using something like nodatime to convert to the local time zone of the client app
8 | public string AccessTokenExpiry => AccessExpiry.ToLocalTime().ToString(CultureInfo.InvariantCulture);
9 |
10 | public int RefreshTokenValidityMinutes => (int)RefreshExpiry.Subtract(DateTime.UtcNow).TotalMinutes;
11 |
12 | //NOTE: most of the time you will be doing this kind of custom transformation on the expiry datetime properties.
13 | // that is why the TokenResponse properties are decorated with [JsonIgnore] attributes.
14 | }
15 | }
--------------------------------------------------------------------------------
/Features/User/Auth/RefreshToken/Data.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Entities;
2 |
3 | namespace User.Auth.RefreshToken;
4 |
5 | public static class Data
6 | {
7 | public static async Task StoreToken(string userId, DateTime refreshExpiry, string refreshToken)
8 | {
9 | await DB.DeleteAsync(rt => rt.UserID == userId);
10 |
11 | await new Dom.RefreshToken
12 | {
13 | UserID = userId,
14 | ExpiryDate = refreshExpiry,
15 | Token = refreshToken
16 | }.SaveAsync();
17 | }
18 |
19 | public static Task TokenIsValid(string userId, string refreshToken)
20 | {
21 | return DB.Find()
22 | .Match(t => t.UserID == userId &&
23 | t.Token == refreshToken &&
24 | t.ExpiryDate >= DateTime.UtcNow)
25 | .ExecuteAnyAsync();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Features/User/Auth/RefreshToken/RefreshToken.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS8618
2 | using MongoDB.Entities;
3 |
4 | namespace Dom;
5 |
6 | public class RefreshToken : Entity
7 | {
8 | public string UserID { get; set; }
9 | public string Token { get; set; }
10 | public DateTime ExpiryDate { get; set; }
11 |
12 | static RefreshToken()
13 | {
14 | //TTL index to automatically purge records after 1 minute once the token has expired
15 | DB.Index()
16 | .Key(x => x.ExpiryDate, KeyType.Ascending)
17 | .Option(x => x.ExpireAfter = TimeSpan.FromMinutes(1))
18 | .CreateAsync();
19 |
20 | //compound index for queries
21 | DB.Index()
22 | .Key(x => x.UserID, KeyType.Ascending)
23 | .Key(x => x.Token, KeyType.Ascending)
24 | .Key(x => x.ExpiryDate, KeyType.Ascending)
25 | .CreateAsync();
26 | }
27 | }
--------------------------------------------------------------------------------
/Features/User/Auth/RefreshToken/UserTokenService.cs:
--------------------------------------------------------------------------------
1 | namespace User.Auth.RefreshToken;
2 |
3 | public class UserTokenService : RefreshTokenService
4 | {
5 | public UserTokenService(IConfiguration config)
6 | {
7 | Setup(x =>
8 | {
9 | x.TokenSigningKey = config["JWTSigningKey"];
10 | x.AccessTokenValidity = TimeSpan.FromMinutes(1);
11 | x.RefreshTokenValidity = TimeSpan.FromHours(1);
12 | x.Endpoint("/user/auth/refresh-token", ep =>
13 | {
14 | ep.Summary(s => s.Description = "this is the refresh token endpoint");
15 | });
16 | });
17 | }
18 |
19 | public override Task PersistTokenAsync(MyTokenResponse rsp)
20 | => Data.StoreToken(rsp.UserId, rsp.RefreshExpiry, rsp.RefreshToken);
21 |
22 | public override async Task RefreshRequestValidationAsync(TokenRequest req)
23 | {
24 | if (!await Data.TokenIsValid(req.UserId, req.RefreshToken))
25 | AddError("The refresh token is not valid!");
26 | }
27 |
28 | public override async Task SetRenewalPrivilegesAsync(TokenRequest request, UserPrivileges privileges)
29 | {
30 | await Task.Delay(100); //simulate a db call
31 | privileges.Claims.Add(new("UserID", request.UserId));
32 | privileges.Permissions.AddRange(new Allow().AllCodes());
33 | }
34 | }
--------------------------------------------------------------------------------
/Features/User/Profile/Data.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Entities;
2 |
3 | namespace User.Profile;
4 |
5 | public static class Data
6 | {
7 | public static Task GetUser(string userID)
8 | => DB.Find()
9 | .MatchID(userID)
10 | .ExecuteSingleAsync();
11 | }
--------------------------------------------------------------------------------
/Features/User/Profile/Endpoint.cs:
--------------------------------------------------------------------------------
1 | namespace User.Profile;
2 |
3 | using Auth;
4 |
5 | public class Endpoint : Endpoint
6 | {
7 | public override void Configure()
8 | {
9 | Get("/user/profile");
10 | Permissions(Allow.User_Profile_View);
11 | }
12 |
13 | public override async Task HandleAsync(Request r, CancellationToken c)
14 | {
15 | var user = await Data.GetUser(r.UserID);
16 |
17 | if (user is null)
18 | await SendNotFoundAsync();
19 | else
20 | await SendAsync(Map.FromEntity(user));
21 | }
22 | }
--------------------------------------------------------------------------------
/Features/User/Profile/Mapper.cs:
--------------------------------------------------------------------------------
1 | namespace User.Profile;
2 |
3 | public class Mapper : Mapper
4 | {
5 | public override Response FromEntity(Dom.User e) => new()
6 | {
7 | Age = e.Age,
8 | Email = e.Email,
9 | Name = e.Name
10 | };
11 | }
--------------------------------------------------------------------------------
/Features/User/Profile/Models.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS8618
2 | using FluentValidation;
3 |
4 | namespace User.Profile;
5 |
6 | public class Request
7 | {
8 | [FromClaim("UserID")]
9 | public string UserID { get; set; }
10 | }
11 |
12 | public class Validator : Validator
13 | {
14 | public Validator()
15 | {
16 | RuleFor(x => x.UserID).NotEmpty();
17 | }
18 | }
19 |
20 | public class Response
21 | {
22 | public string Name { get; set; }
23 | public string Email { get; set; }
24 | public int Age { get; set; }
25 | }
26 |
--------------------------------------------------------------------------------
/Features/User/Signup/Data.cs:
--------------------------------------------------------------------------------
1 | using MongoDB.Entities;
2 |
3 | namespace User.Signup;
4 |
5 | public static class Data
6 | {
7 | public static async Task CreateUser(Dom.User user)
8 | {
9 | await user.SaveAsync();
10 | return user.ID;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Features/User/Signup/Endpoint.cs:
--------------------------------------------------------------------------------
1 | namespace User.Signup;
2 |
3 | public class Endpoint : Endpoint
4 | {
5 | public override void Configure()
6 | {
7 | Post("/user/signup");
8 | AllowAnonymous();
9 | }
10 |
11 | public override async Task HandleAsync(Request r, CancellationToken c)
12 | {
13 | var userID = await Data.CreateUser(Map.ToEntity(r));
14 |
15 | if (string.IsNullOrEmpty(userID))
16 | ThrowError("User creation failed!");
17 |
18 | Response.Message = $"The user [{r.Name}] has been created with ID: {userID}";
19 | }
20 | }
--------------------------------------------------------------------------------
/Features/User/Signup/Mapper.cs:
--------------------------------------------------------------------------------
1 | namespace User.Signup;
2 |
3 | public class Mapper : Mapper
4 | {
5 | public override Dom.User ToEntity(Request r) => new()
6 | {
7 | Age = r.Age,
8 | Email = r.Email,
9 | Password = r.Password, //never store clear passwords in db. always hash/salt before saving.
10 | Name = r.Name
11 | };
12 | }
--------------------------------------------------------------------------------
/Features/User/Signup/Models.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS8618
2 | using FluentValidation;
3 |
4 | namespace User.Signup;
5 |
6 | public class Request
7 | {
8 | public string Name { get; set; }
9 | public string Email { get; set; }
10 | public string Password { get; set; }
11 | public int Age { get; set; }
12 | }
13 |
14 | public class Validator : Validator
15 | {
16 | public Validator()
17 | {
18 | RuleFor(x => x.Name).NotEmpty();
19 | RuleFor(x => x.Email).MinimumLength(5);
20 | RuleFor(x => x.Password).MinimumLength(5).MaximumLength(20);
21 | RuleFor(x => x.Age).GreaterThan(15);
22 | }
23 | }
24 |
25 | public class Response
26 | {
27 | public string Message { get; set; }
28 | }
29 |
--------------------------------------------------------------------------------
/Features/User/User.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS8618
2 | using MongoDB.Entities;
3 |
4 | namespace Dom;
5 |
6 | public class User : Entity
7 | {
8 | public string Name { get; set; }
9 | public string Email { get; set; }
10 | public string Password { get; set; }
11 | public int Age { get; set; }
12 |
13 | static User()
14 | {
15 | DB.Index()
16 | .Key(x => x.Email, KeyType.Ascending)
17 | .Key(x => x.Password, KeyType.Ascending)
18 | .CreateAsync();
19 | }
20 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 FastEndpoints
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | global using FastEndpoints;
2 | global using FastEndpoints.Security;
3 | using FastEndpoints.Swagger;
4 | using MongoDB.Entities;
5 |
6 | var bld = WebApplication.CreateBuilder();
7 | bld.Services
8 | .AddAuthenticationJwtBearer(o=>o.SigningKey = bld.Configuration["JWTSigningKey"])
9 | .AddAuthorization()
10 | .AddFastEndpoints()
11 | .SwaggerDocument(o=>o.AutoTagPathSegmentIndex = 2);
12 |
13 | var app = bld.Build();
14 | app.UseAuthentication()
15 | .UseAuthorization()
16 | .UseFastEndpoints()
17 | .UseSwaggerGen();
18 |
19 | await DB.InitAsync(app.Configuration["MongoAddress"] ?? "localhost");
20 |
21 | app.Run();
--------------------------------------------------------------------------------
/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Refresh-Tokens-Demo": {
4 | "commandName": "Project",
5 | "launchBrowser": true,
6 | "environmentVariables": {
7 | "ASPNETCORE_ENVIRONMENT": "Development"
8 | },
9 | "applicationUrl": "https://localhost:51563;http://localhost:51564"
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Refresh-Tokens-Demo
2 | Demo application showcasing refresh token service in FastEndpoints
3 |
--------------------------------------------------------------------------------
/Refresh-Tokens-Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft.AspNetCore": "Warning"
6 | }
7 | },
8 | "AllowedHosts": "*",
9 | "JWTSigningKey": "_some_very_long_jwt_signing_secret_",
10 | "MongoAddress": "localhost"
11 | }
--------------------------------------------------------------------------------