forked from flow-typed/flow-typed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add redux-oidc v3 types (flow-typed#1347)
* add redux-oidc types * add comment for workaround for pulling in other modules
- Loading branch information
1 parent
e282e41
commit 8419604
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
definitions/npm/redux-oidc_v3.x.x/flow_v0.55.x-/redux-oidc_v3.x.x.js
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,47 @@ | ||
import type { Reducer, Store } from "redux"; | ||
|
||
declare module "redux-oidc" { | ||
declare type UserManager = { | ||
signinRedirect: () => Promise<*>, | ||
signoutRedirect: () => Promise<*> | ||
}; | ||
declare type User<P> = { | ||
expired: ?boolean, | ||
profile: P | ||
}; | ||
declare type UserManagerSettings = {| | ||
client_id: string, | ||
authority: string, | ||
redirect_uri: string, | ||
response_type?: string, | ||
scope?: string, | ||
loadUserInfo?: boolean, | ||
silent_redirect_uri?: string, | ||
automaticSilentRenew?: boolean, | ||
accessTokenExpiringNotificationTime?: number, | ||
silentRequestTimeout?: number, | ||
filterProtocolClaims?: boolean | ||
|}; | ||
declare type OidcReducerState = { | ||
user: ?User<*> | ||
}; | ||
declare type OidcReducer = Reducer<OidcReducerState, *>; | ||
|
||
declare function createUserManager( | ||
settings: UserManagerSettings | ||
): UserManager; | ||
declare var reducer: OidcReducer; | ||
|
||
declare class CallbackComponent extends React$Component<{ | ||
userManager: UserManager, | ||
successCallback: () => mixed, | ||
errorCallback?: () => mixed | ||
}> {} | ||
|
||
declare class OidcProvider extends React$Component<{ | ||
store: Store<*, *>, | ||
userManager: UserManager | ||
}> {} | ||
|
||
declare function processSilentRenew(): void; | ||
} |
68 changes: 68 additions & 0 deletions
68
definitions/npm/redux-oidc_v3.x.x/flow_v0.55.x-/test_redux-oidc.js
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,68 @@ | ||
// @flow | ||
|
||
"use strict"; | ||
const React = require("react"); | ||
const reduxOidc = require("redux-oidc"); | ||
// $ExpectError: flow-typed doesn't support pulling in _other_ modules yet? | ||
const redux = require("redux"); | ||
// This was also attempted, but still no joy. | ||
// See https://github.com/flowtype/flow-typed/issues/1331 | ||
// const redux = require('../../redux_v3.x.x/flow_v0.33.x-/redux_v3.x.x.js') | ||
|
||
const CallbackComponent = reduxOidc.CallbackComponent; | ||
const OidcProvider = reduxOidc.OidcProvider; | ||
|
||
// createUserManager takes a config. | ||
const userManagerConfig = { | ||
client_id: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
authority: "https://some-authority.org/oidc", | ||
redirect_uri: "http:https://base/#/callback", | ||
response_type: "token id_token", | ||
scope: "openid profile email", | ||
loadUserInfo: false, | ||
automaticSilentRenew: true, | ||
silent_redirect_uri: "http:https://base/oidc-silent-renew.html", | ||
accessTokenExpiringNotificationTime: 598 | ||
}; | ||
|
||
const userManager = reduxOidc.createUserManager(userManagerConfig); | ||
|
||
// The UserManager can do redirects for signins/outs. | ||
userManager.signinRedirect(); | ||
userManager.signoutRedirect(); | ||
|
||
// The reducer has a user | ||
const user = reduxOidc.reducer.user; | ||
|
||
// $ExpectError: The user could be null/undefined. | ||
console.log(user.expired); | ||
|
||
if (user) { | ||
console.log(user.expired); | ||
} | ||
|
||
type Action = { | ||
type: "foo" | ||
}; | ||
type State = { | ||
foo: string | ||
}; | ||
// redux-oidc provides some components. | ||
const reducer = (state: State, action: Action) => action; | ||
const store = redux.createStore(redux.combineReducers([reducer])); | ||
|
||
const StatelessComponent = () => { | ||
return ( | ||
<div> | ||
<CallbackComponent | ||
userManager={userManager} | ||
successCallback={() => console.log("success!")} | ||
errorCallback={() => console.log("error!")} | ||
/> | ||
<OidcProvider store={store} userManager={userManager} /> | ||
</div> | ||
); | ||
}; | ||
|
||
// There's a utility function for silent renews. | ||
reduxOidc.processSilentRenew(); |