File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed
packages/@react-oauth/google/src Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @react-oauth/google ' : patch
3+ ---
4+
5+ Add minor CSP support by accepting "nonce" and propagating it to GSI script & inline style
Original file line number Diff line number Diff line change @@ -193,6 +193,7 @@ const hasAccess = hasGrantedAnyScopeGoogle(
193193| Required | Prop | Type | Description |
194194| :------: | ------------------- | ---------- | --------------------------------------------------------------------------- |
195195| ✓ | clientId | ` string ` | [ ** Google API client ID** ] ( https://console.cloud.google.com/apis/dashboard ) |
196+ | | nonce | ` string ` | Nonce applied to GSI script tag. Propagates to GSI's inline style tag |
196197| | onScriptLoadSuccess | ` function ` | Callback fires on load gsi script success |
197198| | onScriptLoadError | ` function ` | Callback fires on load gsi script failure |
198199
Original file line number Diff line number Diff line change @@ -18,11 +18,13 @@ interface GoogleOAuthProviderProps extends UseLoadGsiScriptOptions {
1818
1919export default function GoogleOAuthProvider ( {
2020 clientId,
21+ nonce,
2122 onScriptLoadSuccess,
2223 onScriptLoadError,
2324 children,
2425} : GoogleOAuthProviderProps ) {
2526 const scriptLoadedSuccessfully = useLoadGsiScript ( {
27+ nonce,
2628 onScriptLoadSuccess,
2729 onScriptLoadError,
2830 } ) ;
Original file line number Diff line number Diff line change 11import { useState , useEffect , useRef } from 'react' ;
22
33export interface UseLoadGsiScriptOptions {
4+ /**
5+ * Nonce applied to GSI script tag. Propagates to GSI's inline style tag
6+ */
7+ nonce ?: string ;
48 /**
59 * Callback fires on load [gsi](https://accounts.google.com/gsi/client) script success
610 */
@@ -14,7 +18,7 @@ export interface UseLoadGsiScriptOptions {
1418export default function useLoadGsiScript (
1519 options : UseLoadGsiScriptOptions = { } ,
1620) : boolean {
17- const { onScriptLoadSuccess, onScriptLoadError } = options ;
21+ const { nonce , onScriptLoadSuccess, onScriptLoadError } = options ;
1822
1923 const [ scriptLoadedSuccessfully , setScriptLoadedSuccessfully ] =
2024 useState ( false ) ;
@@ -30,6 +34,7 @@ export default function useLoadGsiScript(
3034 scriptTag . src = 'https://accounts.google.com/gsi/client' ;
3135 scriptTag . async = true ;
3236 scriptTag . defer = true ;
37+ scriptTag . nonce = nonce ;
3338 scriptTag . onload = ( ) => {
3439 setScriptLoadedSuccessfully ( true ) ;
3540 onScriptLoadSuccessRef . current ?.( ) ;
@@ -44,7 +49,7 @@ export default function useLoadGsiScript(
4449 return ( ) => {
4550 document . body . removeChild ( scriptTag ) ;
4651 } ;
47- } , [ ] ) ;
52+ } , [ nonce ] ) ;
4853
4954 return scriptLoadedSuccessfully ;
5055}
You can’t perform that action at this time.
0 commit comments