Jump to content

apiClient.getCurrentUserId()


pir8radio

Recommended Posts

pir8radio

can someone give me a simple javascript example that grabs the current userId value and puts it in a variable please?   

 

 

Link to comment
Share on other sites

Can you explain what you are really trying to accomplish?  There is a whole sequence of things that would need to have happened before you could get a user ID.

Link to comment
Share on other sites

pir8radio

Nothing malicious   :)    I'm talking about getting the userid from an already logged in webgui session. 

 

The script will be injected into existing html responses using nginx, so it will appear to come from the same server as the rest of the html...   I could also use a javascript get of the html5 stored value from "servercreditials3" "userId" if that's easier...

 

Anyway, some requests have the userId=(hash) already in the url..  I would like to make my own embyuserId=(hash) on every request for user tracking..    I have some tracking now using your existing userId=(hash) but want more detail.  

 

For example here are some reports for the last few hours.   I log the userId uri parameter in my server access logs by grabbing the hash and crossing it with the user hashes in the emby user database to give me real user names..    But i just need to attach the hash to every user request..  The easiest for me.. otherwise i have to create user fingerprints and then associate the few userId's that i do get with those prints to group all of the requests... 

 

57e6ea1535903_Screenshotfrom201609241559

 

57e6eb65583ba_Screenshotfrom201609241606

Edited by pir8radio
Link to comment
Share on other sites

pir8radio

no?   script to grab local storage userId value only, and put it in a variable?    Pretty please?   :)

Link to comment
Share on other sites

no?   script to grab local storage userId value only, and put it in a variable?    Pretty please?   :)

 

Pure JavaScript way:

var cred3 = localStorage.getItem('servercredentials3');
var servers = JSON.parse(cred3);

var MyUserIdVariable = servers.Servers[0].UserId;
  • Like 1
Link to comment
Share on other sites

pir8radio

 

Pure JavaScript way:

var cred3 = localStorage.getItem('servercredentials3');
var servers = JSON.parse(cred3);

var MyUserIdVariable = servers.Servers[0].UserId;

 

oh.... huh thanks, I couldnt figure out how to get just the userId value...  Im not the best with js..   thanks ill give it a go!

Link to comment
Share on other sites

pir8radio

@@dcrdev worked perfect thanks!

 

I ended up with:

function GetEmbyuserId() {
    if (localStorage.getItem("servercredentials3") === null) {
	return "null"
}
	var cred3 = localStorage.getItem("servercredentials3");
	var servers = JSON.parse(cred3);
	var EmbyuserId = servers.Servers[0].UserId;
	return EmbyuserId
}
Edited by pir8radio
Link to comment
Share on other sites

  • 3 years later...
vaise

I'm finally messing around with my nginx logs - seeing as I have nothing but time on my hands now.

Iv got a goaccess container reading the logs, and I have $http_x_emby_authorization in the emby logging.

All the hashed Userid= in the logs tho..... how do you convert them to real usernames for your dashboard ?

 

*Ignore - just read this :

 I log the userId uri parameter in my server access logs by grabbing the hash and crossing it with the user hashes in the emby user database to give me real user names..    But i just need to attach the hash to every user request..  The easiest for me.. otherwise i have to create user fingerprints and then associate the few userId's that i do get with those prints to group all of the requests...

Edited by vaise
Link to comment
Share on other sites

pir8radio

I'm finally messing around with my nginx logs - seeing as I have nothing but time on my hands now.

Iv got a goaccess container reading the logs, and I have $http_x_emby_authorization in the emby logging.

All the hashed Userid= in the logs tho..... how do you convert them to real usernames for your dashboard ?

 

*Ignore - just read this :

 I log the userId uri parameter in my server access logs by grabbing the hash and crossing it with the user hashes in the emby user database to give me real user names..    But i just need to attach the hash to every user request..  The easiest for me.. otherwise i have to create user fingerprints and then associate the few userId's that i do get with those prints to group all of the requests...

 

 

you good?     If you don't have a bunch of users you can just create a "file" that contains the hash to text conversion.   If you want that option.

Link to comment
Share on other sites

vaise

I suspect I am out of my depth here.

Or maybe your paid for log analysis tool has way more functions.

goaccess only can read the nginx logs, so I would have to somehow get the real users converted from the hash in nginx and added to the logs.

Link to comment
Share on other sites

  • 2 weeks later...
pir8radio

I suspect I am out of my depth here.

Or maybe your paid for log analysis tool has way more functions.

goaccess only can read the nginx logs, so I would have to somehow get the real users converted from the hash in nginx and added to the logs.

 

you will have to build a text list of your users and hashes either manually or by script using the emby user database.   then let nginx replace those hashes in its log with the actual usernames automatically...  I use a separate file that contains my if/then's lol  its not the most efficient method, but it works well.

 

then just add   include userId.Emby;  above the logging section in the emby server block

 

what it does is as every hit comes into nginx it matches the userid field to whatever hash then changes it to the username prior to writing it to the log. 

so you will want to use special logging like below, you only need to worry about replacing $remote_user with $userId    dont copy exactly below, im doing some other logging, like using the cloudflare IP, and grabbing the enire x_emby_authorization header and pulling stuff out of that as well...  

log_format emby      '$http_cf_connecting_ip - $userId [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $request_time $server_port "$http_x_emby_authorization"';

file in nginx directory called userId.Emby

	set $userId "${arg_userid}";                 # Check/set URI userId value


	# Add new user hash conversions below.

	if ($userId ~ 1djkfsdlkjfsd;lkjfsdl;kj4535545e0) {
	  set $userId Pir8Radio;
	}
	if ($userId ~ 2djkfsdlkjfsd;lkjfsdl;kj4535545e0) {
	  set $userId Guest;
	}
	if ($userId ~ 3djkfsdlkjfsd;lkjfsdl;kj4535545e0) {
	  set $userId Dude;



	#  Below needs to stay put, it adds a - to the log if this field is empty

	if ($userId = '') {
	  set $userId -;
	}

it looks like a lot, but it will make sense as you figure things out. 

Edited by pir8radio
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...