Skip to content

Commit

Permalink
feat(ember-simple-auth): note responseJSON and responseText as deprec…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
BobrImperator committed Dec 26, 2024
1 parent b8cb93e commit 58d499e
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ type MakeRequestData =
| OAuthInvalidateRequestData
| OAuthRefreshRequestData;

interface OAuth2Response extends Response {
/**
* @deprecated 'responseText' is deprecated. This is a legacy AJAX API.
*/
responseText: string;
/**
* @deprecated 'responseJSON' is deprecated. This is a legacy AJAX API.
*/
responseJSON: string;
}

/**
Authenticator that conforms to OAuth 2
([RFC 6749](http://tools.ietf.org/html/rfc6749)), specifically the _"Resource
Expand Down Expand Up @@ -369,7 +380,7 @@ export default class OAuth2PasswordGrantAuthenticator extends BaseAuthenticator
url: string,
data: MakeRequestData,
headers: Record<string, string> = {}
): Promise<OAuthResponseSuccess & { responseText: string } & { responseJSON: string }> {
): Promise<OAuthResponseSuccess> {
headers['Content-Type'] = 'application/x-www-form-urlencoded';

const clientId = this.get('clientId');
Expand Down Expand Up @@ -403,15 +414,13 @@ export default class OAuth2PasswordGrantAuthenticator extends BaseAuthenticator
try {
let json = JSON.parse(text);
if (!response.ok) {
// @TODO: migrate the old AJAX API.
(response as any).responseJSON = json;
(response as OAuth2Response).responseJSON = json;
reject(response);
} else {
resolve(json);
}
} catch (SyntaxError) {
// @TODO: migrate the old AJAX API.
(response as any).responseText = text;
(response as OAuth2Response).responseText = text;
reject(response);
}
});
Expand Down

0 comments on commit 58d499e

Please sign in to comment.