forked from keratin/authn-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oauth: get signing key from provider (keratin#236)
Signing key can be included as a third optional segment in the colon-delimited environment variable strings used for credentials currently. If not provided the existing global oauth signing key is used.
- Loading branch information
Showing
19 changed files
with
274 additions
and
194 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
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 |
---|---|---|
@@ -1,25 +1,41 @@ | ||
package oauth | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Credentials is a configuration struct for OAuth Providers | ||
type Credentials struct { | ||
ID string | ||
Secret string | ||
ID string | ||
Secret string | ||
SigningKey []byte | ||
} | ||
|
||
// NewCredentials parses a credential string in the format `id:string` and returns a Credentials | ||
// suitable for OAuth Provider configuration. | ||
func NewCredentials(credentials string) (*Credentials, error) { | ||
if strings.Count(credentials, ":") != 1 { | ||
return nil, errors.New("Credentials must be in the format `id:string`") | ||
// NewCredentials parses a credential string in the format `id:string:signing_key(optional)` | ||
// and returns a Credentials suitable for OAuth Provider configuration. If no signing key is | ||
// provided the default key is used. | ||
func NewCredentials(credentials string, defaultKey []byte) (*Credentials, error) { | ||
if strings.Count(credentials, ":") < 1 { | ||
return nil, errors.New("Credentials must be in the format `id:string:signing_key(optional)`") | ||
} | ||
strs := strings.SplitN(credentials, ":", 2) | ||
return &Credentials{ | ||
strs := strings.SplitN(credentials, ":", 3) | ||
|
||
c := &Credentials{ | ||
ID: strs[0], | ||
Secret: strs[1], | ||
}, nil | ||
} | ||
|
||
if len(strs) == 3 { | ||
key, err := hex.DecodeString(strs[2]) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to decode signing key: %w", err) | ||
} | ||
c.SigningKey = key | ||
} else { | ||
c.SigningKey = defaultKey | ||
} | ||
return c, nil | ||
} |
Oops, something went wrong.