### Install connectrpc-permify-propelauth Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Command to install the Go library using the go get command. This is the primary way to add the dependency to your Go project. ```bash go get github.com/nrf110/connectrpc-permify-propelauth ``` -------------------------------- ### PropelAuth Authenticator Setup Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Demonstrates how to configure and create a PropelAuth authenticator for use with ConnectRPC Permify interceptors. ```APIDOC ## PropelAuth Authenticator Setup ### Description This section details the process of setting up the PropelAuth authenticator, including configuration parameters and how to integrate it with the ConnectRPC Permify interceptor. ### Method Go Code Example ### Endpoint N/A (Library Integration) ### Parameters #### Request Body N/A ### Request Example ```go package main import ( "log" connectpermify "github.com/nrf110/connectrpc-permify/pkg" propelauth "github.com/nrf110/connectrpc-permify-propelauth/pkg" ) func main() { // Configure PropelAuth config := propelauth.PropelConfig{ AuthURL: "https://your-auth-url.propelauth.com", ApiKey: "your-api-key", } // Create ID extractor for API keys without associated users idExtractor := propelauth.DefaultIDExtractor("service_id") // Create the authenticator authenticator, err := propelauth.NewPropelAuthenticator(config, idExtractor) if err != nil { log.Fatal("Failed to create authenticator:", err) } // Use with ConnectRPC Permify interceptor // Assuming permifyClient is already initialized // var permifyClient *permify.Client // interceptor := connectpermify.NewAuthorizationInterceptor(authenticator, permifyClient) // Apply to your ConnectRPC server // server := connect.NewServer(handler, connect.WithInterceptors(interceptor)) } ``` ### Response #### Success Response (200) N/A (Code execution) #### Response Example N/A ``` -------------------------------- ### Clone Repository Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Bash command to clone the project repository from GitHub. This is the first step in setting up the development environment. ```bash git clone https://github.com/nrf110/connectrpc-permify-propelauth.git cd connectrpc-permify-propelauth ``` -------------------------------- ### Run Tests Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Make command to execute the test suite for the project. This ensures the code functions as expected and helps catch regressions. ```bash make test ``` -------------------------------- ### Basic PropelAuth Configuration for ConnectRPC Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Go code demonstrating how to set up PropelAuth configuration and create a new authenticator for use with a ConnectRPC Permify interceptor. It shows how to handle potential errors during authenticator creation. ```go package main import ( "log" connectpermify "github.com/nrf110/connectrpc-permify/pkg" propelauth "github.com/nrf110/connectrpc-permify-propelauth/pkg" ) func main() { // Configure PropelAuth config := propelauth.PropelConfig{ AuthURL: "https://your-auth-url.propelauth.com", ApiKey: "your-api-key", } // Create ID extractor for API keys without associated users idExtractor := propelauth.DefaultIDExtractor("service_id") // Create the authenticator authenticator, err := propelauth.NewPropelAuthenticator(config, idExtractor) if err != nil { log.Fatal("Failed to create authenticator:", err) } // Use with ConnectRPC Permify interceptor interceptor := connectpermify.NewAuthorizationInterceptor(authenticator, permifyClient) // Apply to your ConnectRPC server // server := connect.NewServer(handler, connect.WithInterceptors(interceptor)) } ``` -------------------------------- ### Accessing Principal Information Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Explains how to retrieve and utilize authenticated user and organization data within ConnectRPC handlers. ```APIDOC ## Accessing Principal Information ### Description This section describes how to access the authenticated principal's information, including user details and active organization data, from the request context within your service handlers. ### Method Go Code Example ### Endpoint N/A (Handler Integration) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```go package main import ( "context" connect "connectrpc.com/connect" propelauth "github.com/nrf110/connectrpc-permify-propelauth/pkg" ) // Assuming MyService and MyRequest/MyResponse are defined elsewhere type MyService struct {} type MyRequest struct {} type MyResponse struct {} func (s *MyService) MyHandler(ctx context.Context, req *connect.Request[MyRequest]) (*connect.Response[MyResponse], error) { principal := propelauth.GetPrincipal(ctx) // Access user information if principal.User != nil { userID := principal.User.ID email := principal.User.Email // ... use user data } // Access organization information if principal.ActiveOrg != nil { orgID := principal.ActiveOrg.ID orgName := principal.ActiveOrg.Name // ... use org data } return connect.NewResponse(&MyResponse{}), nil } ``` ### Response #### Success Response (200) N/A (Handler return) #### Response Example N/A ``` -------------------------------- ### Accessing Principal Information in ConnectRPC Handlers Source: https://github.com/nrf110/connectrpc-permify-propelauth/blob/main/README.md Go code snippet illustrating how to retrieve the authenticated principal (user and organization details) from the request context within a ConnectRPC handler. This allows access to user-specific data for authorization checks. ```go func (s *MyService) MyHandler(ctx context.Context, req *connect.Request[MyRequest]) (*connect.Response[MyResponse], error) { principal := propelauth.GetPrincipal(ctx) // Access user information if principal.User != nil { userID := principal.User.ID email := principal.User.Email // ... use user data } // Access organization information if principal.ActiveOrg != nil { orgID := principal.ActiveOrg.ID orgName := principal.ActiveOrg.Name // ... use org data } return connect.NewResponse(&MyResponse{}), nil } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.