mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
added sso flow
This commit is contained in:
@@ -11,7 +11,7 @@ from backend.blocks.aryshare._api import (
|
||||
FirstComment,
|
||||
SocialPlatform,
|
||||
)
|
||||
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema
|
||||
from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema, BlockType
|
||||
from backend.data.model import SchemaField
|
||||
from backend.integrations.credentials_store import IntegrationCredentialsStore
|
||||
|
||||
@@ -117,6 +117,8 @@ class BaseAyrsharePostBlock(Block):
|
||||
# The set of categories that the block belongs to.
|
||||
# Each category is an instance of BlockCategory Enum.
|
||||
categories={BlockCategory.SOCIAL},
|
||||
# The type of block, this is used to determine the block type in the UI.
|
||||
block_type=BlockType.AYRSHARE,
|
||||
# The schema, defined as a Pydantic model, for the input data.
|
||||
input_schema=BaseAyrsharePostBlock.Input,
|
||||
# The schema, defined as a Pydantic model, for the output data.
|
||||
|
||||
@@ -435,7 +435,7 @@ async def get_ayrshare_sso_url(
|
||||
profile_key = creds_manager.store.get_ayrshare_profile_key(user_id)
|
||||
if not profile_key:
|
||||
# Create new profile if none exists
|
||||
client = AyrshareClient(api_key=settings.secrets.ayrshare_api_key)
|
||||
client = AyrshareClient()
|
||||
profile = client.create_profile(title=f"User {user_id}", messaging_active=True)
|
||||
profile_key = profile.profileKey
|
||||
creds_manager.store.set_ayrshare_profile_key(user_id, profile_key)
|
||||
@@ -448,9 +448,7 @@ async def get_ayrshare_sso_url(
|
||||
)
|
||||
|
||||
# Generate JWT and get SSO URL
|
||||
client = AyrshareClient(
|
||||
api_key=settings.secrets.ayrshare_api_key,
|
||||
)
|
||||
client = AyrshareClient()
|
||||
|
||||
jwt_response = client.generate_jwt(
|
||||
private_key=settings.secrets.ayrshare_jwt_secret,
|
||||
|
||||
@@ -52,8 +52,12 @@ import {
|
||||
TrashIcon,
|
||||
CopyIcon,
|
||||
ExitIcon,
|
||||
} from "@radix-ui/react-icons";
|
||||
|
||||
} from "@radix-ui/react-icons";
|
||||
import {
|
||||
|
||||
FaKey,
|
||||
} from "react-icons/fa";
|
||||
import useCredits from "@/hooks/useCredits";
|
||||
|
||||
export type ConnectionData = Array<{
|
||||
@@ -116,6 +120,8 @@ export const CustomNode = React.memo(
|
||||
const flowContext = useContext(FlowContext);
|
||||
const api = useBackendAPI();
|
||||
const { formatCredits } = useCredits();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
let nodeFlowId = "";
|
||||
|
||||
if (data.uiType === BlockUIType.AGENT) {
|
||||
@@ -249,6 +255,51 @@ export const CustomNode = React.memo(
|
||||
return renderHandles(schema.properties);
|
||||
};
|
||||
|
||||
const generateAryshareSSOHandles = (api: ReturnType<typeof useBackendAPI>) => {
|
||||
const handleSSOLogin = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const { sso_url } = await api.getAyrshareSSOUrl();
|
||||
const popup = window.open(sso_url, "_blank", "popup=true");
|
||||
if (!popup) {
|
||||
throw new Error("Failed to open popup window. Please allow popups for this site.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error getting SSO URL:", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={handleSSOLogin}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? (
|
||||
"Loading..."
|
||||
) : (
|
||||
<>
|
||||
<FaKey className="mr-2 h-4 w-4" />
|
||||
Connect Social Media Accounts
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<NodeHandle
|
||||
title="SSO Token"
|
||||
keyName="sso_token"
|
||||
isConnected={false}
|
||||
schema={{type: "string"}}
|
||||
side="right"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const generateInputHandles = (
|
||||
schema: BlockIORootSchema,
|
||||
nodeType: BlockUIType,
|
||||
@@ -826,8 +877,15 @@ export const CustomNode = React.memo(
|
||||
(A Webhook URL will be generated when you save the agent)
|
||||
</p>
|
||||
))}
|
||||
{data.inputSchema &&
|
||||
generateInputHandles(data.inputSchema, data.uiType)}
|
||||
{data.uiType === BlockUIType.AYRSHARE ? (
|
||||
<>
|
||||
{generateAryshareSSOHandles(api)}
|
||||
{generateInputHandles(data.inputSchema, BlockUIType.STANDARD)}
|
||||
</>
|
||||
) : (
|
||||
data.inputSchema &&
|
||||
generateInputHandles(data.inputSchema, data.uiType)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -580,6 +580,7 @@ export enum BlockUIType {
|
||||
WEBHOOK_MANUAL = "Webhook (manual)",
|
||||
AGENT = "Agent",
|
||||
AI = "AI",
|
||||
AYRSHARE = "Ayrshare",
|
||||
}
|
||||
|
||||
export enum SpecialBlockID {
|
||||
|
||||
Reference in New Issue
Block a user