-
Notifications
You must be signed in to change notification settings - Fork 605
[Go] Added support for flow auth and Firebase auth plugin. #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
e3c5b76
Initial implementation of flow auth.
apascal07 bb0de8e
Update flow.go
apascal07 8aeb4c6
Added Firebase auth plugin.
apascal07 0fe14f6
Cleaned up interface.
apascal07 0195751
Update firebase.go
apascal07 aa0e987
Removed flow auth methods.
apascal07 323ca7d
Update servers_test.go
apascal07 9e83262
Generics overhaul.
apascal07 98a4f34
Added no-auth option.
apascal07 63cd6e0
Renames.
apascal07 fbba953
Update main.go
apascal07 f1bbcf1
Added an option of more define methods.
apascal07 c9f520c
Update flow.go
apascal07 398ebfc
Strongly typed auth, any input.
apascal07 9a253de
Changed FlowAuth to be map[string]any.
apascal07 63f47d5
Renamed Firebase auth file.
apascal07 d8e0e04
Added Firebase auth tests.
apascal07 78715c3
Update main.go
apascal07 16d0dd1
Update flow.go
apascal07 cd54567
Update flow.go
apascal07 8a83700
Added auth context on context.
apascal07 28736bb
Update flow.go
apascal07 d9f96fe
Resolved review comments.
apascal07 c235f8d
Replaced map[string]any with AuthContext.
apascal07 d5a9c1b
Update flow.go
apascal07 d97801f
Added docs.
apascal07 9d062cb
Added docs.
apascal07 d6bd88b
Update flows.go
apascal07 fd03d08
Moved auth docs to separate page.
apascal07 b2feede
Merge branch 'main' into ap-go-flow
apascal07 ed0a8f7
Fix.
apascal07 bd4d917
Update auth_test.go
apascal07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Flow Authentication | ||
|
|
||
| Genkit supports flow-level authentication, allowing you to secure your flows and ensure that only authorized users can execute them. This is particularly useful when deploying flows as HTTP endpoints. | ||
|
|
||
| ## Configuring Flow Authentication | ||
|
|
||
| To add authentication to a flow, you can use the `WithFlowAuth` option when defining the flow. This option takes an implementation of the `FlowAuth` interface, which provides methods for handling authentication and authorization. | ||
|
|
||
| Here's an example of how to define a flow with authentication: | ||
|
|
||
| ```golang | ||
| {% includecode github_path="firebase/genkit/go/internal/doc-snippets/flows.go" region_tag="auth" adjust_indentation="auto" %} | ||
| ``` | ||
|
|
||
| In this example, we're using the Firebase auth plugin to handle authentication. The `policy` function defines the authorization logic, checking if the user ID in the auth context matches the input user ID. | ||
|
|
||
| ## Using the Firebase Auth Plugin | ||
|
|
||
| The Firebase auth plugin provides an easy way to integrate Firebase Authentication with your Genkit flows. Here's how to use it: | ||
|
|
||
| 1. Import the Firebase plugin: | ||
|
|
||
| ```golang | ||
| import "github.com/firebase/genkit/go/plugins/firebase" | ||
| ``` | ||
|
|
||
| 2. Create a Firebase auth provider: | ||
|
|
||
| ```golang | ||
| {% includecode github_path="firebase/genkit/go/internal/doc-snippets/flows.go" region_tag="auth-create" adjust_indentation="auto" %} | ||
| ``` | ||
|
|
||
| The `NewAuth` function takes three arguments: | ||
|
|
||
| - `ctx`: The context for Firebase initialization. | ||
| - `policy`: A function that defines your authorization logic. | ||
| - `required`: A boolean indicating whether authentication is required for direct calls. | ||
|
|
||
| 3. Use the auth provider when defining your flow: | ||
|
|
||
| ```golang | ||
| {% includecode github_path="firebase/genkit/go/internal/doc-snippets/flows.go" region_tag="auth-define" adjust_indentation="auto" %} | ||
| ``` | ||
|
|
||
| ## Handling Authentication in HTTP Requests | ||
|
|
||
| When your flow is deployed as an HTTP endpoint, the Firebase auth plugin will automatically handle authentication for incoming requests. It expects a Bearer token in the Authorization header of the HTTP request. | ||
|
|
||
| ## Running Authenticated Flows Locally | ||
|
|
||
| When running authenticated flows locally or from within other flows, you can provide local authentication context using the `WithLocalAuth` option: | ||
|
|
||
| ```golang | ||
| {% includecode github_path="firebase/genkit/go/internal/doc-snippets/flows.go" region_tag="auth-run" adjust_indentation="auto" %} | ||
| ``` | ||
|
|
||
| This allows you to test authenticated flows without needing to provide a valid Firebase token. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.