Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions docs/advanced-guide/oidc-authentication/page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# OIDC Authentication

OpenID Connect (OIDC) is an identity layer built on top of OAuth 2.0 that enables secure user authentication and transmission of user profile information. It allows clients to verify end-user identities based on authentication performed by an authorization server.

## Overview

Authentication is a critical part of securing web applications by ensuring only authorized users can access protected resources. GoFR supports OIDC integration through middleware that validates Bearer tokens and fetches user information from the OIDC provider.

## Setup

To enable OIDC authentication in GoFR, configure the middleware with your OIDC provider’s UserInfo endpoint. This endpoint is used to validate access tokens and retrieve user claims.

## Usage

Here is an example of enabling OIDC authentication middleware in a GoFR application:

```go
package main

import (
"gofr.dev/gofr/pkg/gofr"
"gofr.dev/gofr/pkg/gofr/http/middleware"
)

func main() {
app := gofr.New()

// Configure OIDC Auth Provider with your UserInfo endpoint
oidcProvider := &middleware.OIDCAuthProvider{
UserInfoEndpoint: "https://your-oidc-provider.com/userinfo",
}

// Use the OIDC middleware for authentication
app.Use(middleware.AuthMiddleware(oidcProvider))

// Define a protected route
app.GET("/profile", func(c *gofr.Context) (any, error) {
userClaims := c.UserInfo() // Access claims set by the middleware
return userClaims, nil
})

app.Run()
}
```

## Error Handling

The middleware handles common error scenarios including:

- Missing or empty Bearer tokens
- Invalid or expired tokens
- Failure to fetch or parse user info from the UserInfo endpoint

Appropriate HTTP 401 (Unauthorized) responses will be returned by the middleware in these cases.

## Tips

- Configure reasonable HTTP client timeouts in the middleware to avoid delays calling the UserInfo endpoint.
- Consider caching user info responses if your application makes frequent authorization checks to improve performance.
- Test your OIDC integration using tokens issued by your authorization server and confirm user claims are correctly propagated.

---

This integration enables robust and standardized authentication flows in GoFR applications using OpenID Connect.
30 changes: 4 additions & 26 deletions docs/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ export const navigation = [
title: 'Hello Server',
href: '/docs/quick-start/introduction' ,
desc: "Getting started with how to write a server using GoFR with basic examples and explanations. Boost your productivity with efficient coding practices and learn to build scalable applications quickly."},

{
title: 'CLI Applications',
href: '/docs/cli/cli',
desc: "Learn to build powerful command-line interface (CLI) applications using GoFr's app.NewCMD(), offering a robust framework for command-line tools."
},

{
title: 'Configuration',
href: '/docs/quick-start/configuration',
Expand Down Expand Up @@ -117,7 +110,7 @@ export const navigation = [
{
title: 'Key Value Store',
href: '/docs/advanced-guide/key-value-store',
desc: "Explore how to implement and manage a key-value store in your GoFr application for fast and efficient data retrieval. Supports BadgerDB, NATS-KV, and DynamoDB."
desc: "Explore how to implement and manage a key-value store in your GoFr application for fast and efficient data retrieval."
},
{
title: 'Dealing with SQL',
Expand Down Expand Up @@ -160,9 +153,9 @@ export const navigation = [
desc: "Discover GoFr auto-enables pprof profiling by leveraging its built-in configurations."
},
{
title: 'Adding Synchronous Startup Hooks',
href: '/docs/advanced-guide/startup-hooks',
desc: "Learn how to seed a database, warm up a cache, or perform other critical setup procedures, synchronously before starting your application."
title: 'OIDC Authentication',
href: '/docs/advanced-guide/oidc-authentication',
desc: 'Learn how to integrate OpenID Connect (OIDC) authentication using GoFR. Covers setup, configuration, and usage for secure authentication flows.'
}
],
},
Expand Down Expand Up @@ -194,11 +187,6 @@ export const navigation = [
href: "/docs/datasources/cockroachdb",
desc: "Learn how to connect to and interact with CockroachDB in GoFr."
},
{
title: "Couchbase",
href: "/docs/datasources/couchbase",
desc: "Learn how to connect to and interact with couchbase database in GoFr."
},
{
title: "DGraph",
href: "/docs/datasources/dgraph",
Expand All @@ -214,11 +202,6 @@ export const navigation = [
href: "/docs/datasources/opentsdb",
desc: "Learn how to connect to and interact with opentsdb database in GoFr."
},
{
title: "OracleDB",
href: "/docs/datasources/oracle",
desc: "Learn how to connect to and interact with oracle database in GoFr."
},
{
title: "ScyllaDB",
href: "/docs/datasources/scylladb",
Expand All @@ -239,11 +222,6 @@ export const navigation = [
href: "/docs/datasources/elasticsearch",
desc: "Learn how to connect to and interact with elasticsearch in GoFr."
},
{
title: "InfluxDB",
href: "/docs/datasources/influxdb",
desc: "Learn how to connect to and interact with influxdb in GoFr."
},
],
},
{
Expand Down
51 changes: 26 additions & 25 deletions go.mod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the version downgrade here

Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module gofr.dev

go 1.25
go 1.24

require (
cloud.google.com/go/pubsub v1.49.0
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/XSAM/otelsql v0.40.0
github.com/XSAM/otelsql v0.39.0
github.com/alicebob/miniredis/v2 v2.35.0
github.com/dgraph-io/dgo/v210 v210.0.0-20230328113526-b66f8ae53a2d
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/go-redis/redismock/v9 v9.2.0
github.com/go-sql-driver/mysql v1.9.3
github.com/gogo/protobuf v1.3.2
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.1
Expand All @@ -20,29 +21,29 @@ require (
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.23.2
github.com/redis/go-redis/extra/redisotel/v9 v9.12.1
github.com/redis/go-redis/v9 v9.12.1
github.com/segmentio/kafka-go v0.4.49
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.63.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0
go.opentelemetry.io/otel v1.38.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0
go.opentelemetry.io/otel/exporters/prometheus v0.60.0
go.opentelemetry.io/otel/exporters/zipkin v1.38.0
go.opentelemetry.io/otel/metric v1.38.0
go.opentelemetry.io/otel/sdk v1.38.0
go.opentelemetry.io/otel/sdk/metric v1.38.0
go.opentelemetry.io/otel/trace v1.38.0
go.uber.org/mock v0.6.0
golang.org/x/oauth2 v0.31.0
golang.org/x/sync v0.17.0
golang.org/x/term v0.34.0
golang.org/x/text v0.29.0
google.golang.org/api v0.249.0
google.golang.org/grpc v1.75.1
google.golang.org/protobuf v1.36.9
github.com/prometheus/client_golang v1.23.0
github.com/redis/go-redis/extra/redisotel/v9 v9.11.0
github.com/redis/go-redis/v9 v9.11.0
github.com/segmentio/kafka-go v0.4.48
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.62.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0
go.opentelemetry.io/otel v1.37.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.37.0
go.opentelemetry.io/otel/exporters/prometheus v0.59.1
go.opentelemetry.io/otel/exporters/zipkin v1.37.0
go.opentelemetry.io/otel/metric v1.37.0
go.opentelemetry.io/otel/sdk v1.37.0
go.opentelemetry.io/otel/sdk/metric v1.37.0
go.opentelemetry.io/otel/trace v1.37.0
go.uber.org/mock v0.5.2
golang.org/x/oauth2 v0.30.0
golang.org/x/sync v0.16.0
golang.org/x/term v0.33.0
golang.org/x/text v0.27.0
google.golang.org/api v0.244.0
google.golang.org/grpc v1.74.2
google.golang.org/protobuf v1.36.6
modernc.org/sqlite v1.38.2
)

Expand Down
11 changes: 7 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgraph-io/dgo/v210 v210.0.0-20230328113526-b66f8ae53a2d h1:abDbP7XBVgwda+h0J5Qra5p2OQpidU2FdkXvzCKL+H8=
github.com/dgraph-io/dgo/v210 v210.0.0-20230328113526-b66f8ae53a2d/go.mod h1:wKFzULXAPj3U2BDAPWXhSbQQNC6FU1+1/5iika6IY7g=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
Expand All @@ -55,8 +56,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -158,8 +159,9 @@ github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFu
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down Expand Up @@ -304,6 +306,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
Expand Down
Loading