-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: support sandbox instances of salesforce #6
Open
zacharygolba
wants to merge
4
commits into
master
Choose a base branch
from
feat-sandbox-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32e01f3
feat: support sandbox instances of salesforce
zacharygolba b3d97bf
feat: use glide.sandbox.json as default when --sandbox is used
zacharygolba dfb604e
chore(docs): update getting started guide
zacharygolba f70af51
fix: environment based auth logic errors
zacharygolba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { handler } from "../utilities"; | ||
|
||
export default handler(async () => { | ||
// noop | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { get } from "lodash"; | ||
|
||
import { MessageType } from "../types"; | ||
import { handler, oauth2, send } from "../utilities"; | ||
|
||
export default handler(async request => { | ||
const { connectionId, domainName, stage } = request.requestContext; | ||
const environment = get(JSON.parse(request.body || "{}"), "data.environment"); | ||
const result = oauth2.configure(environment).getAuthorizationUrl({ | ||
state: JSON.stringify({ connectionId, domainName, stage }), | ||
}); | ||
|
||
await send(request.requestContext, { | ||
data: result, | ||
type: MessageType.Initialize, | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Connection } from "jsforce"; | ||
|
||
import { MessageType } from "../../types"; | ||
import { handler, params, oauth2, send } from "../../utilities"; | ||
|
||
export default handler(async request => { | ||
const environment = params.get(request, "environment"); | ||
const connection = new Connection({ | ||
oauth2: oauth2.configure(environment), | ||
}); | ||
|
||
await connection.authorize(params.require(request, "code")); | ||
await send(JSON.parse(params.require(request, "state")), { | ||
data: { | ||
accessToken: connection.accessToken, | ||
oauth2: oauth2.options(environment), | ||
// @ts-ignore | ||
refreshToken: connection.refreshToken, | ||
}, | ||
type: MessageType.Authenticated, | ||
}); | ||
|
||
return { | ||
message: "You have been successfully logged in", | ||
}; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { handler, oauth2 } from "../../utilities"; | ||
|
||
export default handler(async request => { | ||
const { environment, token } = JSON.parse(request.body || "{}"); | ||
const result = await oauth2.configure(environment).refreshToken(token); | ||
|
||
return { | ||
oauth2: oauth2.options(environment), | ||
accessToken: result.access_token, | ||
refreshToken: result.refresh_token, | ||
}; | ||
}); |
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,60 +0,0 @@ | ||
import { Connection, OAuth2 } from "jsforce"; | ||
import nconf from "nconf"; | ||
|
||
import { handler, params, send } from "./utilities"; | ||
|
||
const oauth2 = new OAuth2(nconf.env("__").get("oauth")); | ||
|
||
const enum MessageType { | ||
Authenticated = "AUTHENTICATED", | ||
Initialize = "INITIALIZE", | ||
} | ||
|
||
export const callback = handler(async request => { | ||
const client = JSON.parse(params.require(request, "state")); | ||
const connection = new Connection({ oauth2 }); | ||
|
||
await connection.authorize(params.require(request, "code")); | ||
|
||
await send(client, { | ||
data: { | ||
accessToken: connection.accessToken, | ||
oauth2: nconf.get("oauth"), | ||
// @ts-ignore | ||
refreshToken: connection.refreshToken, | ||
}, | ||
type: MessageType.Authenticated, | ||
}); | ||
|
||
return { | ||
message: "You have been successfully logged in", | ||
}; | ||
}); | ||
|
||
export const connect = handler(async () => { | ||
// noop | ||
}); | ||
|
||
export const message = handler(async request => { | ||
const state = JSON.stringify({ | ||
connectionId: request.requestContext.connectionId, | ||
domainName: request.requestContext.domainName, | ||
stage: request.requestContext.stage, | ||
}); | ||
|
||
await send(request.requestContext, { | ||
data: oauth2.getAuthorizationUrl({ state }), | ||
type: MessageType.Initialize, | ||
}); | ||
}); | ||
|
||
export const refresh = handler(async request => { | ||
const { token } = JSON.parse(request.body || "{}"); | ||
const results = await oauth2.refreshToken(token); | ||
|
||
return { | ||
oauth2: nconf.get("oauth"), | ||
accessToken: results.access_token, | ||
refreshToken: results.refresh_token, | ||
}; | ||
}); | ||
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export enum Environment { | ||
Default = "default", | ||
Sandbox = "sandbox", | ||
} | ||
|
||
export namespace Environment { | ||
export function from(input?: string): Environment { | ||
switch (input) { | ||
case Environment.Sandbox: { | ||
return Environment.Sandbox; | ||
} | ||
default: { | ||
return Environment.Default; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const enum MessageType { | ||
Authenticated = "AUTHENTICATED", | ||
Initialize = "INITIALIZE", | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was split up into multiple files to make it easier to maintain in the future. Each file in the
events
directory now represents a single lambda event handler.