Skip to content

Commit

Permalink
Merge pull request openshift#129 from rootatdarkstar/fix_jwttoken_exa…
Browse files Browse the repository at this point in the history
…mple_keys_parsing

Fix jwttoken example keys parsing
  • Loading branch information
RangelReale authored Aug 1, 2016
2 parents 82b2206 + 20315b8 commit 413612f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions example/jwttoken/jwttoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
// http://localhost:14000/app

import (
"crypto/rsa"
"fmt"
"github.com/RangelReale/osin"
"github.com/RangelReale/osin/example"
Expand All @@ -14,8 +15,8 @@ import (

// JWT access token generator
type AccessTokenGenJWT struct {
PrivateKey []byte
PublicKey []byte
PrivateKey *rsa.PrivateKey
PublicKey *rsa.PublicKey
}

func (c *AccessTokenGenJWT) GenerateAccessToken(data *osin.AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
Expand Down Expand Up @@ -48,7 +49,21 @@ func (c *AccessTokenGenJWT) GenerateAccessToken(data *osin.AccessData, generater

func main() {
server := osin.NewServer(osin.NewServerConfig(), example.NewTestStorage())
server.AccessTokenGen = &AccessTokenGenJWT{privatekey, publickey}

var err error
var accessTokenGenJWT AccessTokenGenJWT

if accessTokenGenJWT.PrivateKey, err = jwt.ParseRSAPrivateKeyFromPEM(privatekeyPEM); err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}

if accessTokenGenJWT.PublicKey, err = jwt.ParseRSAPublicKeyFromPEM(publickeyPEM); err != nil {
fmt.Printf("ERROR: %s\n", err)
return
}

server.AccessTokenGen = &accessTokenGenJWT

// Authorization code endpoint
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -158,7 +173,7 @@ func main() {
}

var (
privatekey = []byte(`-----BEGIN RSA PRIVATE KEY-----
privatekeyPEM = []byte(`-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA4f5wg5l2hKsTeNem/V41fGnJm6gOdrj8ym3rFkEU/wT8RDtn
SgFEZOQpHEgQ7JL38xUfU0Y3g6aYw9QT0hJ7mCpz9Er5qLaMXJwZxzHzAahlfA0i
cqabvJOMvQtzD6uQv6wPEyZtDTWiQi9AXwBpHssPnpYGIn20ZZuNlX2BrClciHhC
Expand Down Expand Up @@ -186,7 +201,7 @@ CKuHRG+AP579dncdUnOMvfXOtkdM4vk0+hWASBQzM9xzVcztCa+koAugjVaLS9A+
9uQoqEeVNTckxx0S2bYevRy7hGQmUJTyQm3j1zEUR5jpdbL83Fbq
-----END RSA PRIVATE KEY-----`)

publickey = []byte(`-----BEGIN PUBLIC KEY-----
publickeyPEM = []byte(`-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4f5wg5l2hKsTeNem/V41
fGnJm6gOdrj8ym3rFkEU/wT8RDtnSgFEZOQpHEgQ7JL38xUfU0Y3g6aYw9QT0hJ7
mCpz9Er5qLaMXJwZxzHzAahlfA0icqabvJOMvQtzD6uQv6wPEyZtDTWiQi9AXwBp
Expand Down

0 comments on commit 413612f

Please sign in to comment.