Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public OauthToken struct #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client_oauth_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
// and takes care of authenticating OAuth RPC requests on behalf of a client
// (i.e GetBalance())
type clientOAuthAuthentication struct {
Tokens *oauthTokens
Tokens *OauthTokens
BaseUrl string
Client http.Client
}

// ClientOAuth instantiates ClientOAuthAuthentication with the client OAuth tokens
func clientOAuth(tokens *oauthTokens) *clientOAuthAuthentication {
func clientOAuth(tokens *OauthTokens) *clientOAuthAuthentication {
a := clientOAuthAuthentication{
Tokens: tokens,
BaseUrl: config.BaseUrl,
Expand Down
2 changes: 1 addition & 1 deletion coinbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ApiKeyClient(key string, secret string) Client {
}

// OAuthClient instantiates the client with OAuth Authentication
func OAuthClient(tokens *oauthTokens) Client {
func OAuthClient(tokens *OauthTokens) Client {
c := Client{
rpc: rpc{
auth: clientOAuth(tokens),
Expand Down
10 changes: 5 additions & 5 deletions oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ func (o OAuth) CreateAuthorizeUrl(scope []string) string {
}

// RefreshTokens refreshes a users existing OAuth tokens
func (o OAuth) RefreshTokens(oldTokens map[string]interface{}) (*oauthTokens, error) {
func (o OAuth) RefreshTokens(oldTokens map[string]interface{}) (*OauthTokens, error) {
refresh_token := oldTokens["refresh_token"].(string)
return o.GetTokens(refresh_token, "refresh_token")
}

// NewTokens generates new tokens for an OAuth user
func (o OAuth) NewTokens(code string) (*oauthTokens, error) {
func (o OAuth) NewTokens(code string) (*OauthTokens, error) {
return o.GetTokens(code, "authorization_code")
}

// NewTokensRequest generates new tokens for OAuth user given an http request
// containing the query parameter 'code'
func (o OAuth) NewTokensFromRequest(req *http.Request) (*oauthTokens, error) {
func (o OAuth) NewTokensFromRequest(req *http.Request) (*OauthTokens, error) {
query := req.URL.Query()
code := query.Get("code")
return o.GetTokens(code, "authorization_code")
}

// GetTokens gets tokens for an OAuth user specifying a grantType (i.e authorization_code)
func (o OAuth) GetTokens(code string, grantType string) (*oauthTokens, error) {
func (o OAuth) GetTokens(code string, grantType string) (*OauthTokens, error) {

postVars := map[string]string{
"grant_type": grantType,
Expand All @@ -91,7 +91,7 @@ func (o OAuth) GetTokens(code string, grantType string) (*oauthTokens, error) {
return nil, err
}

tokens := oauthTokens{
tokens := OauthTokens{
AccessToken: holder.AccessToken,
RefreshToken: holder.RefreshToken,
ExpireTime: time.Now().UTC().Unix() + holder.ExpiresIn,
Expand Down
4 changes: 2 additions & 2 deletions params.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type ContactsParams struct {
Query string `json:"query,omitempty"`
}

// The OAuth Tokens Struct returned from OAuth Authentication
type oauthTokens struct {
// OauthTokens the OAuth Tokens Struct returned from OAuth Authentication

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: In my opinion, this change does not add value to the comment. Since the OauthTokens struct is on the next line, adding its name to this comment does not seem to add information to this comment. I would remove this, but will approve anyways as it's not hurting anything and is subjective.

type OauthTokens struct {
AccessToken string
RefreshToken string
ExpireTime int64
Expand Down