-
Notifications
You must be signed in to change notification settings - Fork 41
/
psuedo-code.ts
117 lines (110 loc) · 3.37 KB
/
psuedo-code.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import UAuth from '../../packages/js/src'
/**
* Instanciation
*
* @param options
*
* @param options.clientID: string
* TODO: param options.clientSecret?: We don't have it, but we probably will once we deploy more than the one UAuth server
* @param options.redirectUri: string // must be included unless you specify it per request
* @param options.scope: string // Defaults to "openid"
* @param options.fallbackIssuer: string // not required, defaults to https://auth.unstoppabledomains.com
* @param options.postLogoutRedirectUri?: string // not required
* @param options.audience?: string // not required, maybe call it resource?
* @param options.responseType: ResponseType
* @param options.responseMode: ResponseMode
* @param options.maxAge: number // not required
* @param options.clockSkew: number // Defaults to 60
* @param options.networks?: NetworkConfig[] // TODO
* @param options.createIpfsUrl?: (cid: string, path: string) => string
* @param options.resolution: DomainResolver
*/
const uauth = new UAuth({
clientID: 'my_client_id',
clientSecret: 'my_client_secret',
redirectUri: 'https://my-client.com/callback',
scope: 'openid email wallet', // Defaults to 'openid' which just giving access to the the domain name
// resolution: Optional existing resolution library instance
})
/**
* Login
*
* Redirects browser to authorization server. Should be placed on a button.
*
* @param options
*
* @param options.username: string // if unspecified a modal will appear and prompt you for a domain.
* @param options.redirectUri?: string // required either in constructor or here
* @param options.scope?: string // required either in constructor or here
* @param options.audience?: string
* @param options.responseType?: ResponseType
* @param options.responseMode?: ResponseMode
* @param options.state?: T
* @param options.beforeRedirect?(options, url: string): void | Promise<void>
*/
uauth.login().catch(error => {
// some error occured
})
/**
* Login Callback
*
* Uses the window.location in conjuction with variables left in local storage to
* take the authorization code and exchange it for an access token.
*
* @param options
*
* @param options.url: string // if unspecified a will default to window.location.href
*/
uauth
.loginCallback()
.then(user => {
console.log(user)
// user.wallet_type_hint
})
.catch(error => {
// some error occured
})
/**
* Access User info
*
* Returns relavent cached values of access & id tokens in localstorage
*/
uauth
.user()
.then(user => {
console.log(user)
})
.catch(error => {
window.location.assign('/login')
// some error occured while trying to fetch user information, apps should probably log back in
})
/**
* Logout
*
* @param options?
*
* @param options.postLogoutRedirectUri?: string
* @param options.state?: T
* @param options.beforeRedirect?(options,url: string): void | Promise<void>
*/
// Needs polishing
uauth.logout().catch(error => {
// some error occured
})
/**
* TODO: more validation
*
* @param options
*
* @param options.url: string // if unspecified a will default to window.location.href
*/
uauth.logoutCallback().catch(error => {
// some error occured
})
// {
// sub: "domain.crypto",
// email: "[email protected]",
// email_verified: false,
// wallet_address: '0xb8E77cfF40f2942290C2213505Eb2dE733FAcf4C',
// wallet_type_hint: 'web3' | 'walletconnect'
// }