Skip to content

Commit e9cd067

Browse files
committed
Add example app
1 parent e018665 commit e9cd067

File tree

181 files changed

+16990
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+16990
-0
lines changed

Example/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react-native"]
3+
}

Example/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

Example/.eslintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
extends:
3+
- formidable/configurations/es6-react
4+
plugins:
5+
- jest
6+
env:
7+
jest/globals: true
8+
browser: true
9+
rules:
10+
quotes:
11+
- error
12+
- double
13+
no-unsafe-negation:
14+
- off
15+
max-nested-callbacks:
16+
- off
17+
arrow-parens:
18+
- off
19+
filenames/match-regex:
20+
- off

Example/.flowconfig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore unexpected extra "@providesModule"
9+
.*/node_modules/.*/node_modules/fbjs/.*
10+
11+
; Ignore duplicate module providers
12+
; For RN Apps installed via npm, "Libraries" folder is inside
13+
; "node_modules/react-native" but in the source repo it is in the root
14+
.*/Libraries/react-native/React.js
15+
16+
; Ignore polyfills
17+
.*/Libraries/polyfills/.*
18+
19+
[include]
20+
21+
[libs]
22+
node_modules/react-native/Libraries/react-native/react-native-interface.js
23+
node_modules/react-native/flow/
24+
25+
[options]
26+
emoji=true
27+
28+
module.system=haste
29+
30+
munge_underscores=true
31+
32+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
33+
34+
suppress_type=$FlowIssue
35+
suppress_type=$FlowFixMe
36+
suppress_type=$FlowFixMeProps
37+
suppress_type=$FlowFixMeState
38+
suppress_type=$FixMe
39+
40+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
41+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
42+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
43+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
44+
45+
unsafe.enable_getters_and_setters=true
46+
47+
[version]
48+
^0.56.0

Example/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

Example/.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IntelliJ
26+
#
27+
build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
33+
# node.js
34+
#
35+
node_modules/
36+
npm-debug.log
37+
yarn-error.log
38+
39+
# BUCK
40+
buck-out/
41+
\.buckd/
42+
*.keystore
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots

Example/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true
4+
}

Example/.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"javascript.validate.enable": false
3+
}

Example/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Example/App.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// @flow
2+
3+
import React, { Component } from 'react';
4+
import { UIManager, LayoutAnimation } from 'react-native';
5+
import AppAuth from 'react-native-app-auth';
6+
import { Page, Button, ButtonContainer, Form, Heading } from './components';
7+
8+
UIManager.setLayoutAnimationEnabledExperimental &&
9+
UIManager.setLayoutAnimationEnabledExperimental(true);
10+
11+
const scopes = ['openid', 'profile', 'email', 'offline_access'];
12+
13+
type State = {
14+
hasLoggedInOnce: boolean,
15+
accessToken: ?string,
16+
accessTokenExpirationDate: ?string,
17+
refreshToken: ?string
18+
};
19+
20+
export default class App extends Component<{}, State> {
21+
auth = new AppAuth({
22+
issuer: 'https://demo.identityserver.io',
23+
clientId: 'native.code',
24+
redirectUrl: 'io.identityserver.demo:/oauthredirect'
25+
});
26+
27+
state = {
28+
hasLoggedInOnce: false,
29+
accessToken: '',
30+
accessTokenExpirationDate: '',
31+
refreshToken: ''
32+
};
33+
34+
animateState(nextState: $Shape<State>, delay: number = 0) {
35+
setTimeout(() => {
36+
this.setState(() => {
37+
LayoutAnimation.easeInEaseOut();
38+
return nextState;
39+
});
40+
}, delay);
41+
}
42+
43+
authorize = async () => {
44+
try {
45+
const authState = await this.auth.authorize(scopes);
46+
this.animateState(
47+
{
48+
hasLoggedInOnce: true,
49+
accessToken: authState.accessToken,
50+
accessTokenExpirationDate: authState.accessTokenExpirationDate,
51+
refreshToken: authState.refreshToken
52+
},
53+
500
54+
);
55+
} catch (error) {
56+
console.error(error);
57+
}
58+
};
59+
60+
refresh = async () => {
61+
try {
62+
const authState = await this.auth.refresh(this.state.refreshToken, scopes);
63+
this.animateState({
64+
accessToken: authState.accessToken || this.state.accessToken,
65+
accessTokenExpirationDate:
66+
authState.accessTokenExpirationDate || this.state.accessTokenExpirationDate,
67+
refreshToken: authState.refreshToken || this.state.refreshToken
68+
});
69+
} catch (error) {
70+
console.error(error);
71+
}
72+
};
73+
74+
revoke = async () => {
75+
try {
76+
await this.auth.revokeToken(this.state.accessToken, true);
77+
this.animateState({
78+
accessToken: '',
79+
accessTokenExpirationDate: '',
80+
refreshToken: ''
81+
});
82+
} catch (error) {
83+
console.error(error);
84+
}
85+
};
86+
87+
render() {
88+
const { state } = this;
89+
return (
90+
<Page>
91+
{!!state.accessToken ? (
92+
<Form>
93+
<Form.Label>accessToken</Form.Label>
94+
<Form.Value>{state.accessToken}</Form.Value>
95+
<Form.Label>accessTokenExpirationDate</Form.Label>
96+
<Form.Value>{state.accessTokenExpirationDate}</Form.Value>
97+
<Form.Label>refreshToken</Form.Label>
98+
<Form.Value>{state.refreshToken}</Form.Value>
99+
</Form>
100+
) : (
101+
<Heading>{state.hasLoggedInOnce ? 'Goodbye.' : 'Hello, stranger.'}</Heading>
102+
)}
103+
104+
<ButtonContainer>
105+
{!state.accessToken && (
106+
<Button onPress={this.authorize} text="Authorize" color="#DA2536" />
107+
)}
108+
{!!state.refreshToken && <Button onPress={this.refresh} text="Refresh" color="#24C2CB" />}
109+
{!!state.accessToken && <Button onPress={this.revoke} text="Revoke" color="#EF525B" />}
110+
</ButtonContainer>
111+
</Page>
112+
);
113+
}
114+
}

0 commit comments

Comments
 (0)