1.0.51 • Published 4 years ago

coaclient v1.0.51

Weekly downloads
3
License
ISC
Repository
gitlab
Last release
4 years ago

Coursera OAuth2 client

This project is a Node.js library consisting of a client for interacting with Coursera's OAuth2 authorizes APIs.

Requirements

Install Node.js from https://nodejs.org/en/download/

Setup

Before using Coursera's OAuth2 APIs, be sure you know your client id, client secret, and scopes you want for your application. You may create an application at https://accounts.coursera.org/console. When creating the application, set the Redirect URI to be http://localhost:9876/callback?client_id=<your_client_id>.

Usage

(Client-side)

  • Clone project, go to the project folder and build module by run command 'browserify coaclient.js -o bundlecoaclient.js', after that you can use it at client side.

(Server-side) You can use module in different ways:

  • Clone project, add this module to your project, then run command 'npm install' to fetch all dependencies.
  • Open terminal, go to your project folder and download module from npm global repository via command 'npm install coaclient' after you can use it in your project:

// import module
var Coaclient = require('coaclient');
// use static methods
Coaclient.addClientConfig(clientName, clientId, clientSecretKey, scope);
Coaclient.generateAuthTokens(clientName);
Coaclient.getAccessToken(clientName).then(function (tokens) {
   // do something with 'tokens';
}).catch(function (error) {
   // do something if catch error;
});

The Coaclient tries to open the default system browser. The application configuration will be saved to the local file if the request is succeeded. You should check the data you've provided to the library during application configuration if you see any errors in the browser.

If the client was successfully added and configured, you will be able to successfully get authentication tokens for Coursera API. Otherwise, an exception will be thrown telling you to set up your application for API access.

Documentation

Methods:


addClientConfig(clientName, clientId, clientSecretKey, scope);

Create a new client config and save it to the local config file: <home.dir>/.coursera/coaconfig.csv

Parameters:

clientName - Client Name
clientId - Coursera Client ID
clientSecret - Coursera Client Secret Key
scope - by default used "view_profile", for business use "access_business_api".

deleteClientConfig(clientName);

Delete client config from file: <home.dir>/.coursera/coaconfig.csv


generateAuthTokens(clientName);

By default start-server callback listener on port 9876 and get auth tokens from Coursera OAuth API.


getAuthTokens(clientName).then(function (tokens) {
    // do something with 'tokens';
}).catch(function (error) {
    // do something if catch error;
});

Returns: Promise object with refresh, access tokens and expired time from auth token file: <home.dir>/.coursera/<client_name>_oauth2.csv.


getAccessToken(clientName).then(function (accessToken) {
    // do something with 'accessToken';
}).catch(function (error) {
    // do something if catch error;
});

Returns: Promise object with access token from auth token file: <home.dir>/.coursera/<client_name>_oauth2.csv.


getClientConfigs.then(function (listOfClientConfigs) {
    // do something with 'listOfClients';
}).catch(function (error) {
    // do something if catch error;
});

Returns: Promise object with a list of client configs from local file: <home.dir>/.coursera/coaconfig.csv.


getClientConfig(clientNameOrId).then(function (clientConfig) {
    // do something with 'clientConfig';
}).catch(function (error) {
    // do something if catch error;
});

Returns: Promise object with client config from local file: <home.dir>/.coursera/coaconfig.csv.


Bugs / Issues / Feature Requests

Please use the Github issue tracker to document any bugs or other issues you encounter while using this tool.

1.0.51

4 years ago

1.0.50

4 years ago

1.0.49

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.44

4 years ago

1.0.45

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.39

4 years ago

1.0.40

4 years ago

1.0.41

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.30

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago