oauth2-pkce
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -22,4 +22,5 @@ export * from './errors'; | ||
accessToken?: string; | ||
idToken?: string; | ||
refreshToken?: string; | ||
scopes?: Scopes; | ||
refreshToken?: string; | ||
} | ||
@@ -31,2 +32,3 @@ export interface TokenResponse { | ||
refreshToken?: string; | ||
idToken?: string; | ||
} | ||
@@ -47,2 +49,3 @@ export declare const RECOMMENDED_STATE_LENGTH = 32; | ||
getAccessToken(): Promise<AccessContext>; | ||
getTokens(): Promise<AccessContext>; | ||
exchangeAuthCodeForAccessToken(): Promise<AccessContext>; | ||
@@ -49,0 +52,0 @@ exchangeRefreshTokenForAccessToken(): Promise<AccessContext>; |
17
index.js
@@ -77,3 +77,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { accessToken, authorizationCode, refreshToken, scopes } = this.state; | ||
return this.getTokens(); | ||
}); | ||
} | ||
getTokens() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { accessToken, authorizationCode, idToken, refreshToken, scopes } = this.state; | ||
if (authorizationCode) { | ||
@@ -90,3 +95,3 @@ return this.exchangeAuthCodeForAccessToken(); | ||
} | ||
return { accessToken, scopes, refreshToken }; | ||
return Promise.resolve({ accessToken, idToken, refreshToken, scopes }); | ||
}); | ||
@@ -228,6 +233,7 @@ } | ||
} | ||
const { access_token, expires_in, refresh_token, scope } = jsonContent; | ||
const { access_token, expires_in, id_token, refresh_token, scope } = jsonContent; | ||
return { | ||
accessToken: access_token, | ||
expiresIn: expires_in, | ||
idToken: id_token, | ||
refreshToken: refresh_token, | ||
@@ -239,6 +245,9 @@ scope | ||
setTokens(tokenResponse) { | ||
const { accessToken, expiresIn, refreshToken, scope } = tokenResponse; | ||
const { accessToken, expiresIn, idToken, refreshToken, scope } = tokenResponse; | ||
this.state.accessToken = accessToken; | ||
this.state.accessTokenExpiry = (new Date(Date.now() + (parseInt(expiresIn, 10) * 1000))) | ||
.toString(); | ||
if (idToken) { | ||
this.state.idToken = idToken; | ||
} | ||
if (refreshToken) { | ||
@@ -245,0 +254,0 @@ this.state.refreshToken = refreshToken; |
@@ -387,5 +387,12 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.OAuth2Pkce = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.getTokens(); | ||
}); | ||
} | ||
getTokens() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { | ||
accessToken, | ||
authorizationCode, | ||
idToken, | ||
refreshToken, | ||
@@ -409,7 +416,8 @@ scopes | ||
return { | ||
return Promise.resolve({ | ||
accessToken, | ||
scopes, | ||
refreshToken | ||
}; | ||
idToken, | ||
refreshToken, | ||
scopes | ||
}); | ||
}); | ||
@@ -595,2 +603,3 @@ } | ||
expires_in, | ||
id_token, | ||
refresh_token, | ||
@@ -602,2 +611,3 @@ scope | ||
expiresIn: expires_in, | ||
idToken: id_token, | ||
refreshToken: refresh_token, | ||
@@ -613,2 +623,3 @@ scope | ||
expiresIn, | ||
idToken, | ||
refreshToken, | ||
@@ -620,2 +631,6 @@ scope | ||
if (idToken) { | ||
this.state.idToken = idToken; | ||
} | ||
if (refreshToken) { | ||
@@ -622,0 +637,0 @@ this.state.refreshToken = refreshToken; |
{ | ||
"name": "oauth2-pkce", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "An OAuth 2.0 client library for the Authorization Code flow with PKCE", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"types": "*.d.ts", | ||
"files": ["*.js", "*.d.ts"], | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -61,8 +61,10 @@ # OAuth2PKCE client | ||
oauthClient.receiveCode(); | ||
const accessToken = await oauthClient.getAccessToken(); | ||
const tokens = await oauthClient.getTokens(); | ||
``` | ||
This library supports access tokens, refresh tokens, and id tokens. | ||
### Use the tokens | ||
Now you can use the token in order to make requests. There are some mechanisms to help you with that. | ||
Now you can use the token in order to make requests. There are some mechanisms to help you with that. | ||
@@ -69,0 +71,0 @@ #### Automatically Get New Access Token |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82698
1062
126