Coder Social home page Coder Social logo

cdoru / angularspawebapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robisim74/angularspawebapi

0.0 2.0 0.0 1.81 MB

Angular Single Page Application with an ASP.NET Core Web API that uses token authentication

Home Page: http://angularspawebapi.azurewebsites.net

License: MIT License

C# 47.53% HTML 12.39% TypeScript 31.30% CSS 2.31% JavaScript 6.45%

angularspawebapi's Introduction

Angular SPA Web API

Angular 2+ Single Page Application with an ASP.NET Core Web API that uses token authentication. The Resource Owner Password Credentials grant (ROPC) OAuth2 flow is implemented using IdentityServer4, Identity as membership system and claims based authorization with a SQLite database.

Get the Changelog.

Live example and its explanation.

Links

For more complex scenarios, where web services are required by more than one application or third-party applications, IdentityServer4 offers built-in support for OpenID Connent flows.

Links

The same scenarios are also supported by AspNet.Security.OpenIdConnect.Server and openiddict-core.

Links

Project structure

AngularSPAWebAPI ASP.NET Core Web API project

  • wwwroot Root for Angular application deployment
  • app Angular application
  • Controllers
    • IdentityController.cs Identity APIs
    • ValuesController.cs Resources APIs
  • Data Entity Framework migrations
  • Models
    • ApplicationUser.cs Profile data for application users
  • Services
    • DbService.cs Provides method to populate the db
  • build.js Angular app building process for production
  • Config.cs IdentityServer4 configuration
  • IdentityDB.sqlite SQLite database
  • package.json Packages for Angular app
  • Startup.cs Web API configuration
  • tsconfig.json & tsconfig-aot.json TypeScript & ngc compiler options
  • webpack.config.js Webpack configuration file for development & production of Angular app

Installing

Editing

Changing db

To use another database simply:

  • Edit ConnectionStrings in appsettings.json
  • Edit dependencies in project.json:
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",
"Microsoft.EntityFrameworkCore.Sqlite.Design": "1.1.0"
  • Edit in Startup.cs:
services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

Changing the Angular app

Before running the following commands, make sure your configuration for external tools is correct:

and that you have the latest version of npm:

npm install npm@latest -g

From the command line or Package Manager Console or NPM Task Runner, go to the folder that contains package.json.

  • For development, we use JiT compilation, with source maps & Hot Module Replacement:
npm start

And from Visual Studio, start debugging. Make the changes: the browser will update without refreshing.

npm run build

And from Visual Studio, start debugging.

EF Core commands

  • Package Manager Console
Add-Migration [Name] -OutputDir Data/Migrations
Update-Database
  • .NET Core CLI
dotnet ef migrations add [Name] -o Data/Migrations
dotnet ef database update

Swagger

  • Navigate to http://localhost:5000/swagger/v1/swagger.json to see the document generated that describes the endpoints
  • Swagger UI can be viewed by navigating to http://localhost:5000/swagger

To test the APIs, remove the policy from controllers.

Advice

  • You can change the strategy for refresh token
  • You can enable account confirmation and the other Identity services
  • Use a SSL certificate: Insecure passwords
  • If more than one client app requires the Web API, use an interactive flow: IdentityServer4 or the other libraries allow you to scale your application

License

MIT

angularspawebapi's People

Contributors

robisim74 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.