Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Auth/
RegisterAuthenticationProvider.rs

1//! Register an authentication provider in `ApplicationState`. Cocoon-side
2//! providers (GitHub, Microsoft, etc.) call this on activation; later
3//! `GetAuthenticationSession` calls look up the registered handle.
4
5use serde_json::json;
6use tonic::{Response, Status};
7use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType;
8
9use crate::{
10	ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{Empty, RegisterAuthenticationProviderRequest},
13	dev_log,
14};
15
16pub async fn Fn(
17	Service:&CocoonServiceImpl,
18
19	Request:RegisterAuthenticationProviderRequest,
20) -> Result<Response<Empty>, Status> {
21	dev_log!(
22		"cocoon",
23		"[CocoonService] Registering Authentication Provider: id={}",
24		Request.id
25	);
26
27	let Handle = Request
28		.id
29		.as_bytes()
30		.iter()
31		.fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32));
32
33	let DTO = ProviderRegistrationDTO {
34		Handle,
35
36		ProviderType:ProviderType::Authentication,
37
38		Selector:json!([{ "provider": Request.id }]),
39
40		SideCarIdentifier:"cocoon-main".to_string(),
41
42		ExtensionIdentifier:json!(Request.extension_id),
43
44		Options:Some(json!({
45			"label": Request.label,
46			"supportsMultipleAccounts": Request.supports_multiple_accounts,
47		})),
48	};
49
50	Service
51		.environment
52		.ApplicationState
53		.Extension
54		.ProviderRegistration
55		.RegisterProvider(Handle, DTO);
56
57	Ok(Response::new(Empty {}))
58}