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

Unable to provide my own Session to the package #40

Open
aheber opened this issue Aug 20, 2019 · 2 comments
Open

Unable to provide my own Session to the package #40

aheber opened this issue Aug 20, 2019 · 2 comments

Comments

@aheber
Copy link

aheber commented Aug 20, 2019

It seems the package is designed to obtain its own session. I'm working from the idea that a calling org will provide a session for me to use and I do not obtain my own.

To make this work I needed to override part of the Session package but still provide a set of fake Credentials just to get a session created.

I wanted to put this up for discussion before I tried to mangle the package via PR.

I changed session.sessionPasswordResponse to be exported then created an alternate session.Open function that would accept it in and create a Session without trying to login. Staying compatible with the current Session interface so I could pass my session to your systems.

I don't think this solution is very clean because it still requires a sfdc.Configuration object with all the OAuth properties.

// SessionPasswordResponse is the relevant connection details for Salesforce
type SessionPasswordResponse struct {
	AccessToken string `json:"access_token"`
	InstanceURL string `json:"instance_url"`
	TokenType   string
}

// Open is used to authenticate with Salesforce and open a session.  The user will need to
// supply the proper credentials and a HTTP client.
func Open(config sfdc.Configuration, resp *SessionPasswordResponse) (*Session, error) {
	if config.Credentials == nil {
		return nil, errors.New("session: configuration crendentials can not be nil")
	}
	if config.Client == nil {
		return nil, errors.New("session: configuration client can not be nil")
	}
	if config.Version <= 0 {
		return nil, errors.New("session: configuration version can not be less than zero")
	}
	session := &Session{
		response: resp,
		config:   config,
	}

	return session, nil
}
@g8rswimmer
Copy link
Owner

this is not the case. If you look at the session package, you just need to provide the session interfaces to any of the rest api calls. This allows the user to open a session any way that they would like and just implement the interfaces.

@aheber
Copy link
Author

aheber commented Aug 30, 2019

I'm sorry, I don't think I stated my concern well. There is nothing in the package that is ready to accept a raw session & org URL. I did end up implementing something that satisfies the interfaces and leveraged that in my project, a little simpler than what I placed above.

Is there interest in having a built in part of the project to do this? If so, do you have a preference in how it is implemented? I'm happy to do it and get a PR back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants