Class

OAuth2PasswordGrantAuthenticator

OAuth2PasswordGrantAuthenticator()

Constructor

# new OAuth2PasswordGrantAuthenticator()

Authenticator that conforms to OAuth 2 (RFC 6749), specifically the "Resource Owner Password Credentials Grant Type".

This authenticator also automatically refreshes access tokens (see RFC 6749, section 6) if the server supports it.

View Source authenticators/oauth2-password-grant.js, line 12

Extends

Members

String

# static clientId

The client_id to be sent to the authentication server (see https://tools.ietf.org/html/rfc6749#appendix-A.1).

This should only be
used for statistics or logging etc. as it cannot actually be trusted since
it could have been manipulated on the client!
Properties:
Name Type Description
clientId
Default Value:
  • null

View Source authenticators/oauth2-password-grant.js, line 50

Boolean

# static refreshAccessTokens

Sets whether the authenticator automatically refreshes access tokens if the server supports it.

Properties:
Name Type Description
refreshAccessTokens
Default Value:
  • true

View Source authenticators/oauth2-password-grant.js, line 91

Boolean

# static refreshAccessTokensWithScope

Sets whether the authenticator use the scope when refreshing access tokens if the server supports it.

Properties:
Name Type Description
refreshAccessTokensWithScope
Default Value:
  • false

View Source authenticators/oauth2-password-grant.js, line 103

String

# static serverTokenEndpoint

The endpoint on the server that authentication and token refresh requests are sent to.

Properties:
Name Type Description
serverTokenEndpoint
Default Value:
  • '/token'

View Source authenticators/oauth2-password-grant.js, line 62

String

# static serverTokenRevocationEndpoint

The endpoint on the server that token revocation requests are sent to. Only set this if the server actually supports token revocation. If this is null, the authenticator will not revoke tokens on session invalidation.

If token revocation is enabled but fails, session invalidation will be
intercepted and the session will remain authenticated (see
OAuth2PasswordGrantAuthenticator.invalidate.
Properties:
Name Type Description
serverTokenRevocationEndpoint
Default Value:
  • null

View Source authenticators/oauth2-password-grant.js, line 79

Integer

# static tokenRefreshOffset

The offset time in milliseconds to refresh the access token. This must return a random number. This randomization is needed because in case of multiple tabs, we need to prevent the tabs from sending refresh token request at the same exact moment.

When overriding this property, make sure to mark the overridden property
as volatile so it will actually have a different value each time it is
accessed.
Properties:
Name Type Description
tokenRefreshOffset
Default Value:
  • a random number between 5 and 10

View Source authenticators/oauth2-password-grant.js, line 121

Methods

# static authenticate(identification, password, scope, headers) → {Ember.RSVP.Promise}

Authenticates the session with the specified identification, password and optional scope; issues a POST request to the OAuth2PasswordGrantAuthenticator.serverTokenEndpoint and receives the access token in response (see https://tools.ietf.org/html/rfc6749#section-4.3).

If the credentials are valid (and the optionally requested scope is
granted) and thus authentication succeeds, a promise that resolves with the
server's response is returned, otherwise a promise that rejects with the
error as returned by the server is returned.

If the
server supports it, this
method also schedules refresh requests for the access token before it
expires.

The server responses are expected to look as defined in the spec (see
http://tools.ietf.org/html/rfc6749#section-5). The response to a successful
authentication request should be:

```json
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
  "access_token":"2YotnFZFEjr1zCsicMWpAA",
  "token_type":"bearer",
  "expires_in":3600, // optional
  "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA" // optional
}
```

The response for a failing authentication request should be:

```json
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8

{
  "error":"invalid_grant"
}
```

A full list of error codes can be found
[here](https://tools.ietf.org/html/rfc6749#section-5.2).
Parameters:
Name Type Description
identification String

The resource owner username

password String

The resource owner password

scope String | Array

The scope of the access request (see RFC 6749, section 3.3)

headers Object

Optional headers that particular backends may require (for example sending 2FA challenge responses)

View Source authenticators/oauth2-password-grant.js, line 176

A promise that when it resolves results in the session becoming authenticated. If authentication fails, the promise will reject with the server response; however, the authenticator reads that response already so if you need to read it again you need to clone the response object first

Ember.RSVP.Promise

# static invalidate(data) → {Ember.RSVP.Promise}

If token revocation is enabled, this will revoke the access token (and the refresh token if present). If token revocation succeeds, this method returns a resolving promise, otherwise it will return a rejecting promise, thus intercepting session invalidation.

If token revocation is not enabled this method simply returns a resolving
promise.
Parameters:
Name Type Description
data Object

The current authenticated session data

View Source authenticators/oauth2-password-grant.js, line 268

A promise that when it resolves results in the session being invalidated. If invalidation fails, the promise will reject with the server response (in case token revocation is used); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first

Ember.RSVP.Promise

# protected static makeRequest(url, data, headers) → {Promise}

Makes a request to the OAuth 2.0 server.

Parameters:
Name Type Description
url String

The request URL

data Object

The request data

headers Object

Additional headers to send in request

View Source authenticators/oauth2-password-grant.js, line 314

A promise that resolves with the response object

Promise

# static restore(data) → {Ember.RSVP.Promise}

Restores the session from a session data object; will return a resolving promise when there is a non-empty access_token in the session data and a rejecting promise otherwise. If the server issues expiring access tokens and there is an expired access token in the session data along with a refresh token, the authenticator will try to refresh the access token and return a promise that resolves with the new access token if the refresh was successful. If there is no refresh token or the token refresh is not successful, a rejecting promise will be returned.

Parameters:
Name Type Description
data Object

The data to restore the session from

View Source authenticators/oauth2-password-grant.js, line 130

A promise that when it resolves results in the session becoming or remaining authenticated. If restoration fails, the promise will reject with the server response (in case the access token had expired and was refreshed using a refresh token); however, the authenticator reads that response already so if you need to read it again you need to clone the response object first

Ember.RSVP.Promise

Events

# sessionDataUpdated

Triggered when the authenticator refreshed the access token (see RFC 6749, section 6).

Parameters:
Name Type Description
data Object

The updated session data

View Source authenticators/oauth2-password-grant.js, line 26