Giter Club home page Giter Club logo

jwttokenexampleapi's Introduction

Preview:

https://authapi-vfernandes.herokuapp.com/swagger

Todo

  • Refresh token
  • Create roles for users
  • Unit tests

AppSettings Sample

Change the configurations, for DbProvider possible values are SQLServer and PostgreSQL.
Remember of create a appsettings.Production.json and a appsettings.Development.json

{
    "JWT": {
      "Key" :  "afsdkjasjf5434234dlxswafsdklk434orqiwupadav313453123317u-34oew3234irroqwiffv48mfs"
    },
    "DbProvider":"SQLServer", 
    "ConnectionStrings": {
      "SqlServer": "Data Source=localhost;Initial Catalog=JWTAuthentication;Integrated Security=True;",
      "PostgreSQL": "Host=YourServer;Pooling=true;Database=YourDatabase;User Id=YourUser;Password=YourPassword;"
  
    },
    "Logging": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft.AspNetCore": "Warning"
      }
    }
  }

Migrations

Update database

It's necessary to apply the migrations to create the tables in your database.
For SqlServer, change the DbProvider in appsettings for SQLServer and run:

dotnet ef database update  --project JWTAuthentication  --context SqlServerDbContext

For PostgreSQL, change the DbProvider in appsettings for PostgreSQL and run:

dotnet ef database update --project JWTAuthentication --context PostgreSQLDbContext 

If you make any changes in the models

Create a new Migration for PostgreSQL:

dotnet ef migrations add YourMigrationName --project JWTAuthentication  --context PostgreSQLDbContext --output-dir Migrations/PostgreSqlMigrations --verbose

Create a new Migration for SqlServer:

dotnet ef migrations add YourMigrationName --project JWTAuthentication  --context SqlServerDbContext --output-dir Migrations/SqlServerlMigrations --verbose

Run in your machine

   "ConnectionStrings": {
       "DefaultConnection": "Data Source=localhost;Initial Catalog=JWTAuthentication;Integrated Security=True;"
   }
  • Run the command :
dotnet ef database update
  • Run the command
dotnet run --project JWTAuthentication

Publish to heroku

First we need a way to host a database server to use it in the project.
You can create one for free using: https://www.elephantsql.com/\ If using a PostgreSQL server like the one before, you only need to create an appsettings.Production.json (use the appsettings sample) and change the PostgreSQL with your credentials.
For other databases you need to configure the Program.cs.
You will need to install docker:
https://www.docker.com/products/docker-desktop/
And also the heroku CLI:
https://devcenter.heroku.com/articles/heroku-cli
Create an app in heroku and save its name, for example if your app url is : https://authapi-vfernandes.herokuapp.com/ it's name will be auth-api-vfernandes.
Now run:

docker build -t auth-api .

Login to heroku:

heroku login 

Then login to it's container:

heroku container:login

Push the container to heroku:

heroku container:push web -a yourHerokuAppName

Publish it:

heroku container:release web -a yourHerokuAppName

jwttokenexampleapi's People

Contributors

va-fernandes avatar vinicius-fernandes avatar

Watchers

 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.