Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alfex4936/rust-actix-oauth2

Google/Github/NAVER/Kakao OAuth2 login
https://github.com/alfex4936/rust-actix-oauth2

api google jwt kakao login naver oauth oauth2 rust

Last synced: 2 months ago
JSON representation

Google/Github/NAVER/Kakao OAuth2 login

Awesome Lists containing this project

README

        

# πŸš€ OAuth2 Login Demo

![demo](https://github.com/Alfex4936/rust-actix-oauth2/assets/2356749/81ac3ea2-f934-4da6-a01d-4b729e147c1f)

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](https://chocolatey.org/)):

```bash
choco install mkcert
```

**On Linux**:

```bash
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:

```bash
mkcert -install
```

Finally, create a certificate for `localhost`:

```bash
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**:

```bash
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:

```env
CLIENT_ORIGIN=http://localhost:3001
JWT_SECRET=your_secret
...
# Fill other values accordingly.
```

4. **Run the Application**:

```bash
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:

```rust
// ... [snip] ...

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

pub async fn get_naver_user(access_token: &str) -> Result> {
// ... [snip] ...
}
```

## πŸ™Œ Contributions

Let's make authentication easy for everyone!

## πŸ“œ License

This project is licensed under the MIT License - see the [LICENSE](MIT.md) file for details.

---