-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from drophive/feature/synchronous-support
✨ Add synchronous support
- Loading branch information
Showing
15 changed files
with
176 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelogs | ||
## 2.0.0 | ||
* Added synchronous support. | ||
|
||
## 1.0.0 | ||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Upgrading | ||
## From 1.0.0 to 2.0.0 | ||
Change: | ||
```js | ||
import pkceChallenge from 'react-native-pkce-challenge' | ||
``` | ||
To: | ||
```js | ||
import {asyncPkceChallenge} from 'react-native-pkce-challenge' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
const pkceChallenge = require('./src/pkce-challenge') | ||
const asyncPkceChallenge = require('./src/async-pkce-challenge') | ||
const pkceChallenge = require('./src/sync-pkce-challenge') | ||
|
||
module.exports = pkceChallenge | ||
module.exports = { | ||
asyncPkceChallenge: asyncPkceChallenge, | ||
pkceChallenge: pkceChallenge | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const {base64UrlEncode, generateChallenge} = require('./common') | ||
const generateRandomBytes = require('./async-random-bytes') | ||
|
||
function generateVerifier() { | ||
return new Promise(function(resolve, reject) { | ||
generateRandomBytes().then(function(bytes) { | ||
resolve(base64UrlEncode(bytes)) | ||
}) | ||
}) | ||
} | ||
|
||
function asyncPkceChallenge() { | ||
return new Promise(function(resolve, reject) { | ||
generateVerifier().then(function(verifier) { | ||
const challenge = generateChallenge(verifier) | ||
|
||
resolve({ | ||
codeChallenge: challenge, | ||
codeVerifier: verifier | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = asyncPkceChallenge |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const CryptoJS = require('crypto-js') | ||
|
||
function base64UrlEncode(str) { | ||
return str | ||
.replace(/\+/g, '-') | ||
.replace(/\//g, '_') | ||
.replace(/=/g, '') | ||
} | ||
|
||
function generateChallenge(verifier) { | ||
const hash = CryptoJS.SHA256(verifier).toString(CryptoJS.enc.Base64) | ||
|
||
return base64UrlEncode(hash) | ||
} | ||
|
||
module.exports = { | ||
base64UrlEncode: base64UrlEncode, | ||
generateChallenge: generateChallenge | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const {base64UrlEncode, generateChallenge} = require('./common') | ||
const generateRandomBytes = require('./sync-random-bytes') | ||
|
||
function generateVerifier() { | ||
const bytes = generateRandomBytes() | ||
|
||
return base64UrlEncode(bytes) | ||
} | ||
|
||
function pkceChallenge() { | ||
const verifier = generateVerifier() | ||
const challenge = generateChallenge(verifier) | ||
|
||
return { | ||
codeChallenge: challenge, | ||
codeVerifier: verifier | ||
} | ||
} | ||
|
||
module.exports = pkceChallenge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const randomBytes = require('crypto').randomBytes | ||
|
||
function generateRandomBytes() { | ||
const buffer = randomBytes(96) | ||
const bytes = buffer.toString('base64') | ||
|
||
return bytes | ||
} | ||
|
||
module.exports = generateRandomBytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const CryptoJS = require('crypto-js') | ||
|
||
function generateRandomBytes() { | ||
const buffer = CryptoJS.lib.WordArray.random(96) | ||
const bytes = buffer.toString(CryptoJS.enc.Base64) | ||
|
||
return bytes | ||
} | ||
|
||
module.exports = generateRandomBytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const {test} = require('tap') | ||
const {pkceChallenge} = require('../index') | ||
|
||
test('Verifier length must be 128 characters', function(t) { | ||
const challenge = pkceChallenge() | ||
|
||
t.is(challenge.codeVerifier.length, 128) | ||
t.end() | ||
}) | ||
|
||
test('Challenge length must be 43 characters', function(t) { | ||
const challenge = pkceChallenge() | ||
|
||
t.is(challenge.codeChallenge.length, 43) | ||
t.end() | ||
}) | ||
|
||
test('Verifier must match the pattern', function(t) { | ||
const pattern = /^[A-Za-z\d\-._~]{43,128}$/ | ||
const challenge = pkceChallenge() | ||
|
||
t.match(challenge.codeVerifier, pattern) | ||
t.end() | ||
}) | ||
|
||
test('Challenge must not have [=+/]', function(t) { | ||
const challenge = pkceChallenge() | ||
|
||
t.doesNotHave(challenge.codeChallenge, '=') | ||
t.doesNotHave(challenge.codeChallenge, '+') | ||
t.doesNotHave(challenge.codeChallenge, '/') | ||
t.end() | ||
}) |