-
Notifications
You must be signed in to change notification settings - Fork 18
Refresh token functionality #132
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
Draft
MythicalFish
wants to merge
11
commits into
main
Choose a base branch
from
refresh-token-2
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cb3a5d2
Gets code value successfully
MythicalFish 5f29a82
Partially working state
MythicalFish 6ad8705
Fixes
MythicalFish 192a66a
Fixes/refactor
MythicalFish b9a14bb
UI update
MythicalFish cad0ad2
Refactoring
MythicalFish 4448a22
Cleanup
MythicalFish 44f3eef
Cleanup
MythicalFish 341cbe4
Refactor, fixes
MythicalFish 99b0fc6
Fix comment
MythicalFish 82a7951
Refactor
MythicalFish 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
// import fetch from "node-fetch"; | ||
|
||
import { STORAGE_KEY } from "./AuthProvider"; | ||
import { | ||
AUTH0_CLIENT_ID, | ||
AUTH0_CLIENT_SECRET, | ||
AUTH0_DOMAIN | ||
} from "../constants"; | ||
import { Auth0TokenResponse } from "./getAccessToken"; | ||
import { ExtensionContext } from "vscode"; | ||
import { AuthSession } from "./AuthProvider/types"; | ||
|
||
const refreshAccessToken = async ( | ||
session: AuthSession, | ||
context: ExtensionContext | ||
): Promise<string | undefined> => { | ||
const refreshToken = session.refreshToken; | ||
if (!refreshToken) return undefined; | ||
|
||
try { | ||
const data = new URLSearchParams([ | ||
["grant_type", "refresh_token"], | ||
["client_id", AUTH0_CLIENT_ID], | ||
["client_secret", AUTH0_CLIENT_SECRET], | ||
["refresh_token", refreshToken] | ||
]); | ||
|
||
const response = await fetch(`${AUTH0_DOMAIN}/oauth/token`, { | ||
method: "POST", | ||
headers: { "content-type": "application/x-www-form-urlencoded" }, | ||
body: data.toString() | ||
}); | ||
|
||
const tokens = (await response.json()) as Auth0TokenResponse; | ||
const { access_token, refresh_token } = tokens; | ||
if (!access_token) throw new Error(`No new access token`); | ||
|
||
const updatedSession: AuthSession = { | ||
...session, | ||
accessToken: access_token, | ||
refreshToken: refresh_token || session.refreshToken | ||
}; | ||
await context.secrets.store(STORAGE_KEY, JSON.stringify([updatedSession])); | ||
return access_token; | ||
} catch (err) { | ||
console.log("🔴 Failed to refresh token", err); | ||
return undefined; | ||
} | ||
return undefined; | ||
}; | ||
|
||
export default refreshAccessToken; |
This file contains hidden or 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,4 +1,14 @@ | ||
export const SEQERA_PLATFORM_URL = `https://cloud.seqera.io`; | ||
// TODO: Restore to cloud.seqera.io | ||
export const SEQERA_PLATFORM_URL = `https://pr-8246.dev-tower.net`; | ||
export const SEQERA_API_URL = `${SEQERA_PLATFORM_URL}/api`; | ||
export const SEQERA_HUB_API_URL = `https://hub.seqera.io`; | ||
export const SEQERA_INTERN_API_URL = `https://intern.seqera.io`; | ||
|
||
// TODO: Use env var to store the Auth0 secret | ||
// TODO: Update to production Auth0 app | ||
// TODO: Security implications of rolling up this secret into the built extension | ||
export const AUTH0_CLIENT_SECRET = | ||
"tZ3N8vHuvpLQlzdGEhel4Vz5DeluNNyTtid-2jFBdDiXmIGNbX9yhjDmQ2Pg6VT-"; | ||
export const AUTH0_CLIENT_ID = "7PJnvIXiXK3HkQR43c4zBf3bWuxISp9W"; | ||
export const AUTH0_SCOPES = "openid profile email offline_access"; | ||
export const AUTH0_DOMAIN = `seqera-development.eu.auth0.com`; |
This file contains hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
src/webview/WebviewProvider/lib/platform/clearPlatformData.ts
This file contains hidden or 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 { ExtensionContext, WebviewView } from "vscode"; | ||
|
||
const clearPlatformData = async ( | ||
view: WebviewView["webview"] | undefined, | ||
context: ExtensionContext | ||
) => { | ||
view?.postMessage({ authState: {} }); | ||
const vsCodeState = context.workspaceState; | ||
vsCodeState.update("platformData", {}); | ||
}; | ||
|
||
export default clearPlatformData; |
This file contains hidden or 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 hidden or 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
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.
My thoughts:
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.
Providing a client secret is not needed when the app is defined as public. Can you try to make it work without this parameter?
As @tcrespog said, PKCE is used to mitigate the risks of now being able to manage a secret key. It is enabled by default.