Client library for NPR Identity Service
npm install --save @datafire/npr_identity
let npr_identity = require('@datafire/npr_identity').create({
access_token: "",
refresh_token: "",
client_id: "",
client_secret: "",
redirect_uri: ""
});
.then(data => {
console.log(data);
});
The entry point to user-specific information
Exchange the code passed to your redirect URI for an access_token
npr_identity.oauthCallback({
"code": ""
}, context)
- input
object
- code required
string
- code required
- output
object
- access_token
string
- refresh_token
string
- token_type
string
- scope
string
- expiration
string
- access_token
Exchange a refresh_token for an access_token
npr_identity.oauthRefresh(null, context)
This action has no parameters
- output
object
- access_token
string
- refresh_token
string
- token_type
string
- scope
string
- expiration
string
- access_token
After a successful call, this returns a User document with an updated list of affiliations.
npr_identity.postFollowing({
"Authorization": "",
"body": null
}, context)
- input
object
- Authorization required
string
: Your access token from the Authorization Service. Should start withBearer
, followed by a space, followed by the token. - body required Affiliation
- Authorization required
- output UserDocument
Right now, only the primary station can be changed. Previously selected stations will not be deleted, but the new station will be moved to first in the array.
npr_identity.updateStations({
"Authorization": ""
}, context)
- input
object
- Authorization required
string
: Your access token from the Authorization Service. Should start withBearer
, followed by a space, followed by the token. - body
array
- items
integer
- items
- Authorization required
- output UserDocument
After a successful login, the client should send a GET
call approximately once an hour to refresh the user data.
npr_identity.getUser({
"Authorization": ""
}, context)
- input
object
- Authorization required
string
: Your access token from the Authorization Service. Should start withBearer
, followed by a space, followed by the token.
- Authorization required
- output UserDocument
This can and should only be used by clients who have access to the temporary_user
grant type.
Third-party developers do not have access to this grant type by default, and will not need this endpoint.
npr_identity.inheritFromTempUser({
"Authorization": "",
"temp_user": 0
}, context)
- input
object
- Authorization required
string
: Your access token from the Authorization Service. Should start withBearer
, followed by a space, followed by the token. - temp_user required
integer
: The temporary user's ID before the user registered or logged in
- Authorization required
- output UserDocument
- AbstractCDocLink
- href required
string
: The link to be followed - content-type required
string
: The MIME type of the response of this link
- href required
- AbstractLink
object
- href required
string
: The link to be followed
- href required
- Affiliation
object
: A program (aggregation) that a given user has shown an affiliation with- daysSinceLastListen
integer
: The number of days since a user last listened to a story from this aggregation. Absent if user never listened to the aggregation. - following required
boolean
: Whether or not the user is following the aggregation. When changing affiliation status, the client is expected to toggle this value and then send the entire object back. - href required
string
: A link to more details about the program from the NPR Story API - id required
string
: A unique identifier for the aggregation (program) - notif_following
array
: The topic in Firebase Cloud Messaging to which the device should subscribe if it supports notifications and the user wants notifications about the podcasts they follow.- items
string
- items
- notif_rated
array
: The topic in Firebase Cloud Messaging to which the device should subscribe if it supports notifications and the user wants notifications about the podcasts they have highly rated.- items
string
- items
- rating
number
: The user's average rating for this affiliation on a scale of 0-1. Absent if user never listened to the aggregation. - title
string
: The title for the aggregation (program)
- daysSinceLastListen
- Algolia
object
: Parameters for querying the Algolia Search SDK for content- apiKey required
string
: A search API key for this user
- apiKey required
- Cohort
object
: An experimental grouping for User Experience A/B Testing- id required
string
: A short ID for this cohort; ignored on a PUT - name required
string
: A text string identifying the cohort, useful for metrics; ignored on a PUT - public
string
: For internal use only; represents the current configuration file being used by the Listening Service - test
string
: For internal use only; represents the test configuration file being used by the Listening Service
- id required
- CollectionDocument
object
: Base Collection.Doc+JSON output- attributes required
object
- errors required
array
: A list of encountered errors, ignored on POST, PUT- items
object
- items
- href required
string
: A URL representation of the resource; should generally be ignored by clients unless noted otherwise - items required
array
- items
object
- items
- links required
object
- version required
string
: The version of the Collection.Doc+JSON spec being used
- attributes required
- Error
object
: A serialized version of any error encountered when processing this request- code required
integer
: The error code - debug
string
: Additional debug information if debug mode is turned on - text
string
: The error description
- code required
- ErrorDocument: A Collection.doc+JSON representation of an error result from an API call
- attributes required
object
- errors required
array
: A list of encountered errors, ignored on POST, PUT- items
object
- items
- href required
string
: A URL representation of the resource; should generally be ignored by clients unless noted otherwise - items required
array
- items
object
- items
- links required
object
- version required
string
: The version of the Collection.Doc+JSON spec being used - attributes
object
: Ignore; will be empty for errors - errors
array
: A list of encountered errors, ignored on POST, PUT- items Error
- items
array
: Ignore; will be empty for errors- items
object
- items
- links
object
: Ignore; will be empty for errors
- attributes required
- Organization
object
: A station that a user has an affiliation with- call required
string
: Station call letters - city required
string
: A short description of the station's main market city - displayName required
string
: A short displayable text field for the end user, strictly text; ignored on PUT - donationUrl
string
: Station donation page URL - id required
string
: Some unique identifier for the organization for the user - logo
string
: Station logo image url - notif_org
array
: The topic in Firebase Cloud Messaging to which the device should subscribe if it supports notifications and the user wants notifications about their localized station.- items
string
- items
- serviceId
string
: Some unique identifier for the user's organization's primary service, or null if the org has no services - smallLogo
string
: Station logo image url
- call required
- UserData
object
: Object; see description of a user object below- affiliations
array
: Program(s) that the user has positively interacted with- items Affiliation
- algolia required
array
: Use this information to search Algolia for stories- items Algolia
- cohort required Cohort
- email
string
: The user's email address - firstName
string
: The user's first name - id required
string
: Some unique identifier for the user - lastName
string
: The user's last name - organizations required
array
: User's chosen NPR Member Station(s)- items Organization
- totalListeningTime
string
: Internal use only. User's total listening time across all platforms.
- affiliations
- UserDocument
- attributes required
object
- errors required
array
: A list of encountered errors, ignored on POST, PUT- items
object
- items
- href required
string
: A URL representation of the resource; should generally be ignored by clients unless noted otherwise - items required
array
- items
object
- items
- links required
object
- version required
string
: The version of the Collection.Doc+JSON spec being used - attributes UserData
- items
array
: Not used, ignored on a PUT- items
object
- items
- links
object
: A list of links, not used by the Identity Service; ignored on a PUT
- attributes required