Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/alfex4936/rust-actix-oauth2
- Owner: Alfex4936
- License: mit
- Created: 2023-08-06T05:54:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-23T11:13:28.000Z (over 1 year ago)
- Last Synced: 2024-04-21T09:08:30.505Z (10 months ago)
- Topics: api, google, jwt, kakao, login, naver, oauth, oauth2, rust
- Language: Rust
- Homepage:
- Size: 640 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
---