Programmatically login user

I have my portal for the instructors that should use a particular admin account to let the portal users add students. In the D2L instance, these users are regular teachers.

Auth 2.0 doesn't fit the task.

I used the instructions from the following link.

https://community.brightspace.com/s/article/API-Cookbook-Headless-Non-Interactive-Web-Service-Workflow

It says:
"You need to manually harvest the user tokens using a utility such as the API Test Tool (https://apitesttool.desire2learnvalence.com/) to authenticate with your LMS."

This is where I am stuck. The tool does NOT return the token, and it doesn't store the token in the cache either. The token in Local Storage expires in an hour.

Please, help.

Best Answers

  • Tatiana.M.51
    Tatiana.M.51 Posts: 5 🌱
    Answer ✓

    @Ian.P.710 Thanks for the recommendation; I am using OAuth2.0 for now, which does not satisfy the requirements because I had to give more privileges to the users. I cannot restrict these users to a particular Department. The whole point of the custom application was to keep the users as teachers in the LMS with as small privileges as possible and give them a way to create new classes and add the students through the app only to a particular LMS template.

  • Ian.P.710
    Ian.P.710 Posts: 34 image
    Answer ✓

    So you will initially need to login with the user account used for the service user, if you have sso you can bypass that with the Brightspacedomain/d2l/login?noredirect=1 to get to the local login page. login with the service user account and password get the refresh token then use that in your ASP.net code to get the new accesstoken make sure both are stored on the server, then the api's should not require any additional login as long as the refresh token does not expire, it is good for up to 30days as per standard Oauth2.

  • Ian.P.710
    Ian.P.710 Posts: 34 image
    Answer ✓

    Ok so the access token itself will by default last 1 hour you can set it up to be longer if needed but not recommended. If the access token expires then you get a error at which point you trade in the refresh token to get a new access token and refresh token. As long as that trade in occurs at least once in the 30 days from the last time it was updated then should should always be able to connect without the need to re login the service account.

Answers