Skip to content

Commit 7a2b197

Browse files
authored
Merge pull request #2867 from djames-bloom/fix/google-oauth-port
fix: Correct inconsistencies with oauth2-google recipe
2 parents 1265882 + 349774c commit 7a2b197

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

oauth2-google/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ This example demonstrates how to implement Google OAuth2 authentication in a Fib
3232

3333
4. Create a `.env` file in the root directory and add your Google OAuth credentials:
3434
```env
35+
APP_PORT=3300
3536
GOOGLE_CLIENT_ID=your_client_id
3637
GOOGLE_CLIENT_SECRET=your_client_secret
37-
GOOGLE_REDIRECT_URL=http://localhost:3000/api/auth/google/callback
38+
GOOGLE_REDIRECT_URL=http://localhost:3300/api/auth/google/callback
3839
```
3940

4041
## Running the Application
@@ -44,7 +45,7 @@ This example demonstrates how to implement Google OAuth2 authentication in a Fib
4445
go run main.go
4546
```
4647

47-
2. The server will start on `http://localhost:3000`.
48+
2. The server will start on `http://localhost:3300`.
4849

4950
## Endpoints
5051

@@ -57,12 +58,12 @@ This example demonstrates how to implement Google OAuth2 authentication in a Fib
5758
5859
### Redirect to Google Login
5960
```sh
60-
curl -X GET http://localhost:3000/api/
61+
curl -X GET http://localhost:3300/api/
6162
```
6263
6364
### Google OAuth2 Callback
6465
```sh
65-
curl -X GET http://localhost:3000/api/auth/google/callback?state=state&code=code
66+
curl -X GET http://localhost:3300/api/auth/google/callback?state=state&code=code
6667
```
6768
6869
## Packages Used

oauth2-google/auth/auth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
// ConfigGoogle to set config of oauth
1818
func ConfigGoogle() *oauth2.Config {
1919
conf := &oauth2.Config{
20-
ClientID: config.Config("Client"),
21-
ClientSecret: config.Config("Secret"),
22-
RedirectURL: config.Config("redirect_url"),
20+
ClientID: config.Config("GOOGLE_CLIENT_ID"),
21+
ClientSecret: config.Config("GOOGLE_CLIENT_SECRET"),
22+
RedirectURL: config.Config("GOOGLE_REDIRECT_URL"),
2323
Scopes: []string{
2424
"https://www.googleapis.com/auth/userinfo.email",
2525
}, // you can use other scopes to get more data

oauth2-google/example.env

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Client = "" ## google client , get it from https://console.developers.google.com/
2-
Secret = "" # secret of the client
3-
redirect_url = "" # redirect url you added in your google oauth api, make sure the url is same including the port, should match the route of callback
1+
APP_PORT = "3300" ## port on which the app will run
2+
GOOGLE_CLIENT_ID = "" ## google client , get it from https://console.developers.google.com/
3+
GOOGLE_CLIENT_SECRET = "" # secret of the client
4+
GOOGLE_REDIRECT_URL = "" # redirect url you added in your google oauth api, make sure the url is same including the port, should match the route of callback

oauth2-google/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"log"
5+
6+
"fiber-oauth-google/config"
47
"fiber-oauth-google/router"
58

69
"github.com/gofiber/fiber/v2"
@@ -9,7 +12,13 @@ import (
912

1013
func main() {
1114
godotenv.Load()
15+
16+
port := config.Config("APP_PORT")
17+
if port == "" {
18+
port = "3300"
19+
}
20+
1221
app := fiber.New()
1322
router.Routes(app)
14-
app.Listen(":3300")
23+
log.Fatal(app.Listen(":" + port))
1524
}

0 commit comments

Comments
 (0)