You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/authentication.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,25 +13,25 @@ The code for the ID/Key Authentication can be found in the [idkeyauth.js](../src
13
13
```
14
14
* Once the SDK is imported we can create application context using the Instance URL, the Application Key and the Application Id. The Application Key and Application Id are received when an application is registered in Brightspace using the 'Manage Extensibility'tool. The code for creating this context is:
15
15
```javascript
16
-
var appContext = new d2l.ApplicationContext(configs.instanceUrl, configs.applicationId, configs.applicationKey);
16
+
const appContext = new d2l.ApplicationContext(configs.instanceUrl, configs.applicationId, configs.applicationKey);
17
17
```
18
18
* The ```/idkeyauth``` route exists in the project to initiate the ID/Key Authentication protocol using the created application context. Whenthis route is navigated to in the browser the user is redirected to the Learning Environment where they are pompted to accept the application's ability to make APIs on their behalf. You can see in the callback that we call the [```createUserContext```](https://github.com/Brightspace/valence-sdk-javascript/blob/master/lib/valence.js#L266) which grabs userId and userKey from the query parameters returned from Brightspace.
19
19
* Once they have accepted the terms the user is redirected to the ```/idkeycallback``` route where the received userKey and userId are stored in a cookie so that subsequent requests can be signed using this context. The follwing code is how the context is setup again and used:
20
20
21
21
```javascript
22
22
// Grab the UserId and UserKey from the cookie.
23
-
var userId = req.cookies[configs.cookieName].userId;
24
-
var userKey = req.cookies[configs.cookieName].userKey;
The code for the OAuth 2.0 implementation can be found in the [oauth.js](../src/authorization/oauth.js) file. Outof the box there are many supported OAuth 2.0 libraries that you can use in order to make your authenticated requests and support you through the authentication workflow. One thing to keep in mind is that OAuth 2.0 requires the calling application to be granted ```scopes``` that represent what routes the OAuth client can execute.
34
+
The code for the OAuth 2.0 implementation can be found in the [oauth.js](../src/authorization/oauth.js) file. Outof the box there are many supported OAuth 2.0 libraries that you can use in order to make your authenticated requests and support you through the authentication workflow. One thing to keep in mind is that OAuth 2.0 requires the calling application to be granted ```scopes``` that represent what routes the OAuth client is authorized to access.
35
35
36
36
Currently for the samples the following scopes:
37
37
*```core:*:*```
@@ -41,9 +41,9 @@ The following is the workflow the sample has implemented:
41
41
* The first order of business is to attain an authorization code from the [Authorization Endpoint](http://docs.valence.desire2learn.com/basic/oauth2.html#setting-up-oauth-2-0-authentication). In order to recieve an auth code there are several configurations that need to be sent as query parameters. The following code illustrates this:
42
42
```javascript
43
43
// Using the imported 'querystring' library, create the query parameter list passing in the required variables.
44
-
var authCodeParams = querystring.stringify({
45
-
response_type: "code",
46
-
redirect_uri: configs.getRedirectUri(req),
44
+
const authCodeParams = querystring.stringify({
45
+
response_type: 'code',
46
+
redirect_uri: helpers.getRedirectUri(req),
47
47
client_id: configs.clientId,
48
48
scope: configs.authCodeScope,
49
49
state: configs.state
@@ -55,24 +55,24 @@ The following is the workflow the sample has implemented:
55
55
* Once the user has granted the application permission the user is redirected back to the ```/oauthcallback```route. In the callback the recieved Authorization Code is exchanged for an Access Token by calling the [Token Endpoint](http://docs.valence.desire2learn.com/basic/oauth2.html#setting-up-oauth-2-0-authentication) that can then be used to make API calls. The following code is responsible for this exchange:
56
56
```javascript
57
57
// Retrieve the authorization code from the query parameter.
58
-
var authorizationCode = req.query.code;
58
+
const authorizationCode = req.query.code;
59
59
60
60
// Verify that the state passed into the request for an Auth code matches the state passed back to the callback.
61
-
var state = req.query.state;
61
+
const state = req.query.state;
62
62
if (state !== configs.state) {
63
-
console.log("The state value from the authorization request was incorrect.");
64
-
res.status(500).send({ error: "STATE mistmatch - authorization request could not be completed." });
63
+
console.log('The state value from the authorization request was incorrect.');
64
+
res.status(500).send({ error: 'STATE mistmatch - authorization request could not be completed.' });
65
65
return;
66
66
}
67
67
68
68
// Set the values that will be sent to the Token Endpoint through the body of the request.
69
-
var payload = querystring.stringify({
70
-
grant_type: "authorization_code",
69
+
const payload = querystring.stringify({
70
+
grant_type: 'authorization_code',
71
71
redirect_uri: configs.getRedirectUri(req),
72
72
code: authorizationCode
73
73
});
74
74
75
-
// Using the 'superagent' library with the clientId and ClientSecret sent through the headers as Basic Authorization and the payload sent as the body.
75
+
// Using the 'superagent' library with the client_id and client_secret sent through the headers as Basic Authorization and the payload sent as the body.
76
76
request
77
77
.post(configs.tokenEndpoint)
78
78
.auth(configs.clientId, configs.clientSecret)
@@ -81,10 +81,10 @@ The following is the workflow the sample has implemented:
@@ -95,17 +95,17 @@ The following is the workflow the sample has implemented:
95
95
* Now that the Access Token has been saved in the cookie, it can be retrieved later and added as an 'Authorization' header inAPIrequests. The following is an example of this:
96
96
```javascript
97
97
// Retrieve access token from the cookie.
98
-
var accessToken = req.cookies[configs.cookieName].accessToken;
Copy file name to clipboardExpand all lines: docs/configurations.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ The [index.html]() page has several hardcoded values that indicate to the underl
48
48
*```moduleId``` can be updated to the module in content where you would like the new file to be added.
49
49
* Note: if you are changing the values for the content route be sure to checkout the [content.js](../src/content.js) file in order to update the topic data block to point to the proper content location ('Url' field):
0 commit comments