Coder Social home page Coder Social logo

rust-actix-oauth2's Introduction

πŸš€ OAuth2 Login Demo

demo

This project serves as a demo for implementing OAuth2 login functionality using multiple providers like Kakao, Naver, Google, and GitHub. Along with OAuth authentication, it also demonstrates how to create users in the database after successful authentication.

이 ν”„λ‘œμ νŠΈλŠ” 카카였, 넀이버, ꡬ글, κΉƒν—ˆλΈŒμ™€ 같은 μ—¬λŸ¬ μ œκ³΅μ—…μ²΄λ₯Ό μ‚¬μš©ν•˜μ—¬ OAuth2 둜그인 κΈ°λŠ₯을 κ΅¬ν˜„ν•˜κΈ° μœ„ν•œ 데λͺ¨λ‘œ μ‚¬μš©λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

OAuth 인증 외에도 인증이 μ„±κ³΅ν•œ ν›„ λ°μ΄ν„°λ² μ΄μŠ€μ— μ‚¬μš©μžλ₯Ό μƒμ„±ν•˜λŠ” 방법도 λ³΄μ—¬μ€λ‹ˆλ‹€.

πŸ“ Features

  • OAuth Authentication with multiple providers:

    • GitHub (κΉƒν—™)
    • Google (ꡬ글)
    • Kakao (카카였)
    • Naver (넀이버)
    • :)
  • User Management: Creating users in the database post-authentication.

  • Token Management: JWT-based token issuance and validation for authenticated users.

🌱 Setup

  1. Install mkcert:

    First, you need to install mkcert for creating a local certificate for HTTPS development.

    On Windows (using Chocolatey):

    choco install mkcert

    On Linux:

    sudo apt install libnss3-tools
    wget -O mkcert https://github.com/FiloSottile/mkcert/releases/download/v1.4.0/mkcert-v1.4.0-linux-amd64
    chmod +x mkcert
    sudo mv mkcert /usr/local/bin/

    Next, install the local CA:

    mkcert -install

    Finally, create a certificate for localhost:

    mkcert localhost

    This will generate two files: localhost.pem (the certificate) and localhost-key.pem (the private key). Remember the location of these files as you might need to reference them in your application for HTTPS.

  2. Clone the Repository:

    git clone https://github.com/Alfex4936/rust-actix-oauth2.git
    cd rust-actix-oauth2
  3. Setup Environment Variables:

    Copy the sample .env content and set the appropriate values for your OAuth application:

    CLIENT_ORIGIN=http://localhost:3001
    JWT_SECRET=your_secret
    ...
    # Fill other values accordingly.
  4. Run the Application:

    cargo install cargo-watch
    
    cargo watch -q -c -w src/ -x run

    Hosted at https://localhost:8080. (Not on http://)


Note: Ensure that your application is configured to use the generated localhost.pem and localhost-key.pem files when serving via HTTPS. This can often be done in the web framework's settings or configuration.

πŸ” Example: Naver OAuth2

To get an insight into how the OAuth flow works, here's a snippet for Naver OAuth:

// ... [snip] ...

pub async fn get_naver_oauth_token(
    authorization_code: &str,
    data: &web::Data<AppState>,
) -> Result<BasicOauthToken, Box<dyn Error>> {
    // ... [snip] ...
}

pub async fn get_naver_user(access_token: &str) -> Result<NaverUserResult, Box<dyn Error>> {
    // ... [snip] ...
}

πŸ™Œ Contributions

Let's make authentication easy for everyone!

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


rust-actix-oauth2's People

Contributors

alfex4936 avatar

Stargazers

 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.