Skip to content

Instantly share code, notes, and snippets.

View vaygeth89's full-sized avatar

Abdulmohsen Alkhamees vaygeth89

View GitHub Profile
@vaygeth89
vaygeth89 / main.dart
Created October 11, 2019 23:40
Flutter for web part1
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(
@vaygeth89
vaygeth89 / appsettings.json
Last active November 17, 2020 19:28
tutorial-dotnet-JWTProtectedAPI
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"jwtBearerTokenSettings": {
@vaygeth89
vaygeth89 / Startup.cs
Last active November 17, 2020 20:43
tutorial-dotnet-JWTProtectedAPI ConfigureServices()
//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;
@vaygeth89
vaygeth89 / Startup.cs
Created November 17, 2020 20:26
tutorial-dotnet-JWTProtectedAPI setUpBearerJwtAuth()
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 =>
@vaygeth89
vaygeth89 / Startup.cs
Created November 17, 2020 20:32
tutorial-dotnet-JWTProtectedAPI Configure()
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
@vaygeth89
vaygeth89 / AppDbContext.cs
Created November 17, 2020 20:34
tutorial-dotnet-JWTProtectedAPI AppDbContext
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)
{
@vaygeth89
vaygeth89 / AccountController.cs
Last active November 18, 2020 21:30
tutorial-dotnet-JWTProtectedAPI AccountController Setup
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;
@vaygeth89
vaygeth89 / AccountController.cs
Last active November 18, 2020 21:52
tutorial-dotnet-JWTProtectedAPI SignUp() Action
//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
@vaygeth89
vaygeth89 / SignUpData.cs
Created November 18, 2020 21:43
tutorial-dotnet-JWTProtectedAPI
namespace JWTProtectedAPI.ViewModels
{
public class SignUpData
{
public string Username { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
}
@vaygeth89
vaygeth89 / AccountController.cs
Created November 18, 2020 21:55
tutorial-dotnet-JWTProtectedAPI
//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