So, the way the model works at a high level is as a three-legged auth model:
- You have a real user with a browser
- You have a third-party service or application that the user can visit (typically) that wants to make Valence API calls on behalf of that user
- You have the back-end LMS
When the real user visits the 3rd party app, before it can make API calls, it needs to ask the LMS for a User ID/Key pair to go with its App ID/Key pair so it can make API calls on behalf of the user. To do this, it redirects the user's browser to the LMS' "login path" to ensure that the LMS "knows" who the user/browser is:
- If the user's browser already has a web session withe LMS, then the LMS can say "I know who the user is" and send the right User ID/Key pair to the 3rd party app.
- If the user's browser doesn't yet have a session, then the LMS can seek to authenticate the user using the standard way for that LMS; THEN it can send the right User ID/Key pair back to the 3rd party app.
(Note that, in both cases, the User ID/Key pair gets generated specifically for THAT user and THAT app: it's not transferable to any other App ID/Key pair.)
This three-legged auth system makes good sense in the case where you really do have three separate parties. In cases like yours, where you want to write a (headless) IT service app that has no real "currently operating user with their web browser", we typically recommend that you create a service account -- a special purpose, "user" and "role" that only gets used for your service application.
So, in this case, you need to have a way to go through the above auth process every single time you need a valid User ID/Key pair for this service "user". There are a bunch of ways to do that, but they all involve having (at some point) a real user with a real browser stand up and play the part of that third leg in the auth process.
Typically what you do is either use a locally hosted version of one of our simple samples, or our online "API Test Tool" (
https://apitesttool.desire2learnvalence.com/), or an interactive Python session with our Python SDK (as in the auth walkthrough I pointed to). Typically, for best security, we'd recommend that you do this process inside a secure environment, so the API Test Tool is perhaps not the best solution, especially if you're not going to connect with HTTPS, because it's sitting out on the internet. However, if you use HTTPS to connect it to your LMS, it's probably sufficiently safe.
For the process of "gathering a User ID/Key pair" you need to use your OWN App ID/Key credentials (that is, the pair you have received for the app/service you are writing).
If you're doing it interactively, you create an app context with those credentials. If you're using a sample, or the online tool, you provide your own App ID/Key pair as the ones to use (not the default ones in the form: those are a single set of public keys for demo purposes). You have to provide the host name of your LMS, and the port to call on. Then you go through the "auth process":
- If you're using an interactive session with the Python SDK, you create an "authentication URL" that you'll cut and paste into your browser... in order to do this, you also need to provide a "callback URL" telling the LMS where to send the User ID/Key -- we suggest localhost because that will go back to the computer where your browser is, and likely your browser will complain it can't find the URL, but you can then copy the completed URL out of the address bar.
- If you're using the sample or online tool, the "callback URL" is hidden to you -- the form provides it automatically: the User ID/Key pair will get sent back to the web server running the sample/online tool.
When passing back the User ID/Key pair, the LMS will put them as query parameters onto that "callback URL" you provided in the request you just sent.
- If you're using the online tool or a sample, the tool/sample should automagically decompose this callback URL, peel out the credentials and show them to you.
- If you're using an interactive Python session, the LMS will redirect to "localhost" and tack on the User ID/Key pair in query parameters. Copy the entire URL from the browser's address bar, and feed that back into your Python session to create the "user context" -- this will peel the User ID/Key out of that result URI, and create a user context for you that you can use to interactively make API calls... you can also inspect it to see what the User ID/Key pair are, save them to disk, and so forth.
In any case, you have no successfully "gathered a User ID/Key pair" for YOUR service account to go with YOUR App ID/Key. You can cache that in a safe place accessible to your admin script/app (like in a configuration file). We highly recommend that you treat your app's App ID/Key pair and all User ID/Keys that go with it as highly sensitive information -- with those tokens ANYONE can make a call to your LMS pretending to be your App as a valid user, so you wan to put them in a safe place visible only to a small number of people and to the script/app that needs to use them.
Whenever the password for this service account changes you will need to go through this process again to gather a new User ID/Key pair. If your LMS has API tokens set to expire in a fixed time, then you'll also need to re-do this process when that time elapses. LMSes by default have this expiry time set to "indefinite" and the User ID/Key tokens expire only when the user's password changes, or the site admin denies access to third party apps for that user.
I hope this clarifies the picture for you.