-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ManageTokens): manage tokens does not work for http [#953]
- Loading branch information
Showing
3 changed files
with
84 additions
and
16 deletions.
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
32 changes: 32 additions & 0 deletions
32
packages/ui/src/ui/containers/ManageTokens/ManageTokensPasswordModal/password-strategies.ts
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,32 @@ | ||
import axios from 'axios'; | ||
import {sha256} from '../../../utils/sha256'; | ||
|
||
type PasswordStrategy = (password: string) => Promise<string>; | ||
|
||
const regularPasswordStrategy = (username: string, ytAuthCluster: string) => { | ||
return async (password: string): Promise<string> => { | ||
const hashedPassword = await sha256(password); | ||
await axios.post(`/api/yt/${ytAuthCluster}/login`, { | ||
username, | ||
password, | ||
}); | ||
|
||
return hashedPassword; | ||
}; | ||
}; | ||
|
||
const sha256PasswordStrategy = () => { | ||
return async (sha256Password: string): Promise<string> => { | ||
return sha256Password; | ||
}; | ||
}; | ||
|
||
export function createPasswordStrategy( | ||
username: string, | ||
ytAuthCluster: string, | ||
isSha256Mode: boolean, | ||
): PasswordStrategy { | ||
return isSha256Mode | ||
? regularPasswordStrategy(username, ytAuthCluster) | ||
: sha256PasswordStrategy(); | ||
} |
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