package osin

import (
	"encoding/base64"
	"strings"

	"github.com/satori/go.uuid"
)

// AuthorizeTokenGenDefault is the default authorization token generator
type AuthorizeTokenGenDefault struct {
}

func removePadding(token string) string {
	return strings.TrimRight(token, "=")
}

// GenerateAuthorizeToken generates a base64-encoded UUID code
func (a *AuthorizeTokenGenDefault) GenerateAuthorizeToken(data *AuthorizeData) (ret string, err error) {
	token := uuid.NewV4()
	return removePadding(base64.URLEncoding.EncodeToString(token.Bytes())), nil
}

// AccessTokenGenDefault is the default authorization token generator
type AccessTokenGenDefault struct {
}

// GenerateAccessToken generates base64-encoded UUID access and refresh tokens
func (a *AccessTokenGenDefault) GenerateAccessToken(data *AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
	token := uuid.NewV4()
	accesstoken = removePadding(base64.URLEncoding.EncodeToString(token.Bytes()))

	if generaterefresh {
		rtoken := uuid.NewV4()
		refreshtoken = removePadding(base64.URLEncoding.EncodeToString(rtoken.Bytes()))
	}
	return
}

package osin

import (
	"encoding/base64"
	"strings"

	"github.com/pborman/uuid"
)

// AuthorizeTokenGenDefault is the default authorization token generator
type AuthorizeTokenGenDefault struct {
}

func removePadding(token string) string {
	return strings.TrimRight(token, "=")
}

// GenerateAuthorizeToken generates a base64-encoded UUID code
func (a *AuthorizeTokenGenDefault) GenerateAuthorizeToken(data *AuthorizeData) (ret string, err error) {
	token := uuid.NewRandom()
	return removePadding(base64.URLEncoding.EncodeToString([]byte(token))), nil
}

// AccessTokenGenDefault is the default authorization token generator
type AccessTokenGenDefault struct {
}

// GenerateAccessToken generates base64-encoded UUID access and refresh tokens
func (a *AccessTokenGenDefault) GenerateAccessToken(data *AccessData, generaterefresh bool) (accesstoken string, refreshtoken string, err error) {
	token := uuid.NewRandom()
	return removePadding(base64.URLEncoding.EncodeToString([]byte(token))), nil

	if generaterefresh {
		rtoken := uuid.NewRandom()
		refreshtoken = removePadding(base64.URLEncoding.EncodeToString([]byte(rtoken)))
	}
	return
}

Switch uuid to original implementation
Switch uuid to original implementation

The original code.google.com go-uuid package has now been migrated to github by Paul Borman, a Googler and a Golang core contributor.