This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'dart:html' as html; // importing the HTML proxying library and named it as html | |
import 'dart:js' as js; // importing the Javascript proxying library and named it as js | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Logging": { | |
"LogLevel": { | |
"Default": "Information", | |
"Microsoft": "Warning", | |
"Microsoft.Hosting.Lifetime": "Information" | |
} | |
}, | |
"AllowedHosts": "*", | |
"jwtBearerTokenSettings": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//rest of Startup.cs code | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SqlServerDb"))); | |
services.AddIdentity<IdentityUser, IdentityRole>(options => | |
{ | |
//! Change your security Policy here to suits your policy | |
options.Password.RequireUppercase = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setUpBearerJwtAuth(IServiceCollection services) | |
{ | |
//Fetch JWT configuration from appsettings.json | |
var jwtSection = Configuration.GetSection("jwtBearerTokenSettings"); | |
//Parse jwtSection from appsettings.json into Concrete Class "JWTBearerTokenSettings" | |
services.Configure<JWTBearerTokenSettings>(jwtSection); | |
var jwtBearerTokenSettings = jwtSection.Get<JWTBearerTokenSettings>(); | |
var key = Encoding.ASCII.GetBytes(jwtBearerTokenSettings.SecretKey); | |
services.AddAuthentication(options => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseRouting(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | |
using Microsoft.AspNetCore.Identity; | |
namespace JWTProtectedAPI.Models | |
{ | |
public class AppDbContext : IdentityDbContext<IdentityUser> | |
{ | |
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Linq; | |
using System.Security.Claims; | |
using System.Text; | |
using System.Threading.Tasks; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Rest of the AccountController | |
[HttpPost] | |
[Route("sign-up")] | |
public async Task<ActionResult> SignUp(SignUpData signUpData) | |
{ | |
try | |
{ | |
//Todo add your business validation here | |
//! You may want to edit catched exceptions block to handle failed scenarios |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace JWTProtectedAPI.ViewModels | |
{ | |
public class SignUpData | |
{ | |
public string Username { get; set; } | |
public string Email { get; set; } | |
public string Password { get; set; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Rest of the SignUp() and GenerateJWTToken() methods | |
[HttpPost] | |
[Route("sign-in")] | |
public async Task<ActionResult> SignIn(SignInData signInData) | |
{ | |
try | |
{ | |
//Todo add your business validation here |
OlderNewer