library/src/network/httpd/BP-HTTPdSessions.cc
// Creates an anonymous session which only grants access to xsrf
// token generation.  This provides xsrf tokens which can be utilized
// with a pre-authentication environment.  Typically this is used to
// prevent xsrf on login forms while still allowing login.
Creates an anonymous session which only grants access to xsrf
token generation.  This provides xsrf tokens which can be utilized
with a pre-authentication environment.  Typically this is used to
prevent xsrf on login forms while still allowing login.
Creates an anonymous session which only grants access to xsrf token generation . This provides xsrf tokens which can be utilized with a pre - authentication environment . Typically this is used to prevent xsrf on login forms while still allowing login .
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionCreateAnonymousGuest
(
		P_BP_HTTPD_SESSION httpd
)
{
	if(!httpd)
		return NULL;
	P_BP_HTTPD_USER tmp_user = NULL;
	char *tmp_user_name = BP_GenRandomUUID();
	char *tmp_password  = BP_GenRandomUUID();
	char *tmp_user_salt = BP_GenRandomUUID();
    BP_HTTPdUserAdd
    (
            httpd,
			BP_HTTPD_USER_ACCESS_ANONYMOUS_GUEST,
			BP_HTTPD_USER_TYPE_ANONYMOUS_GUEST,
            BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256,
			tmp_user_name,
			tmp_password,
			tmp_user_salt,
            "tmp_guest@localhost",
            "temporary_guest",
            "guest"
    );
	P_BP_HTTPD_USER user_lookup = BP_HTTPdUserLookup
	(
			httpd,
			tmp_user_name,
			tmp_password,
			NULL,
			NULL,
			NULL
	);
	if(!user_lookup)
		return NULL;
	if(user_lookup->session)
	{
		if(!BP_HTTPdSessionExpired((P_BP_HTTPD_USER_SESSION)user_lookup->session))
		{
			return (P_BP_HTTPD_USER_SESSION) user_lookup->session;
		}
		BP_HTTPdSessionDestroy(httpd, (P_BP_HTTPD_USER_SESSION) user_lookup->session);
		user_lookup->session = NULL;
	}
	P_BP_HTTPD_USER_SESSION session = (P_BP_HTTPD_USER_SESSION) NULL;
	size_t default_xsrf_token_count = 10;
	session = BP_HTTPdSessionAdd
	(
			httpd,
			BP_HTTPD_USER_SESSION_TYPE_ANONYMOUS_GUEST,
			user_lookup,
			BP_MINUTE,
			default_xsrf_token_count
	);
	printf("\n Looked up user ok?: %p - %s", user_lookup, user_lookup->username);
	return session;
}
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionCreateAnonymousGuest ( P_BP_HTTPD_SESSION httpd ) { if ( ! httpd ) return NULL ; P_BP_HTTPD_USER tmp_user = NULL ; char * tmp_user_name = BP_GenRandomUUID ( ) ; char * tmp_password = BP_GenRandomUUID ( ) ; char * tmp_user_salt = BP_GenRandomUUID ( ) ; BP_HTTPdUserAdd ( httpd , BP_HTTPD_USER_ACCESS_ANONYMOUS_GUEST , BP_HTTPD_USER_TYPE_ANONYMOUS_GUEST , BP_HTTPD_USER_PASSWORD_HASH_TYPE_SHA256 , tmp_user_name , tmp_password , tmp_user_salt , " " , " " , " " ) ; P_BP_HTTPD_USER user_lookup = BP_HTTPdUserLookup ( httpd , tmp_user_name , tmp_password , NULL , NULL , NULL ) ; if ( ! user_lookup ) return NULL ; if ( user_lookup -> session ) { if ( ! BP_HTTPdSessionExpired ( ( P_BP_HTTPD_USER_SESSION ) user_lookup -> session ) ) { return ( P_BP_HTTPD_USER_SESSION ) user_lookup -> session ; } BP_HTTPdSessionDestroy ( httpd , ( P_BP_HTTPD_USER_SESSION ) user_lookup -> session ) ; user_lookup -> session = NULL ; } P_BP_HTTPD_USER_SESSION session = ( P_BP_HTTPD_USER_SESSION ) NULL ; size_t default_xsrf_token_count = 10 ; session = BP_HTTPdSessionAdd ( httpd , BP_HTTPD_USER_SESSION_TYPE_ANONYMOUS_GUEST , user_lookup , BP_MINUTE , default_xsrf_token_count ) ; printf ( " \n " , user_lookup , user_lookup -> username ) ; return session ; }
Creates an anonymous session which only grants access to xsrf
token generation.
Creates an anonymous session which only grants access to xsrf token generation .
// ensure we have a daemon // create temporary user for this session // generate a temporary username and password // attempt to add guest user (will be expired later in the main application loop) // Attempts to lookup the new temporary lookup. // ensure we can lookup the user // check if we already have a session // check if the session is expired // if the session isn't expired, return it // destroy the user session // set session ptr to null // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add New Session %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // session // 10 tokens seems large enough for any and all tasks // add new anon session, lives for 1 minute max to prevent backup // return the session