-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a Noncer interface to allow custom noncers * Default to Base64Noncer (no change, recommended) * Add HexNoncer for providers that don't accept non-alphanumeric nonces
- Loading branch information
1 parent
14b83d0
commit e32d262
Showing
6 changed files
with
66 additions
and
31 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
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
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,34 @@ | ||
package oauth1 | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/base64" | ||
"encoding/hex" | ||
) | ||
|
||
// Noncer provides random nonce strings. | ||
type Noncer interface { | ||
Nonce() string | ||
} | ||
|
||
// Base64Noncer reads 32 bytes from crypto/rand and | ||
// returns those bytes as a base64 encoded string. | ||
type Base64Noncer struct{} | ||
|
||
// Nonce provides a random nonce string. | ||
func (n Base64Noncer) Nonce() string { | ||
b := make([]byte, 32) | ||
rand.Read(b) | ||
return base64.StdEncoding.EncodeToString(b) | ||
} | ||
|
||
// HexNoncer reads 32 bytes from crypto/rand and | ||
// returns those bytes as a base64 encoded string. | ||
type HexNoncer struct{} | ||
|
||
// Nonce provides a random nonce string. | ||
func (n HexNoncer) Nonce() string { | ||
b := make([]byte, 32) | ||
rand.Read(b) | ||
return hex.EncodeToString(b) | ||
} |
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