mirror of
https://github.com/TECHNOFAB11/svelte-oidc.git
synced 2025-12-11 23:50:06 +01:00
chore: code style fixes and documentation updates.
This commit is contained in:
parent
77fd4d289d
commit
08dc5a96cd
4 changed files with 19 additions and 9 deletions
23
README.md
23
README.md
|
|
@ -30,20 +30,29 @@ import {
|
||||||
logout,
|
logout,
|
||||||
userInfo,
|
userInfo,
|
||||||
} from '@dopry/svelte-oidc';
|
} from '@dopry/svelte-oidc';
|
||||||
|
|
||||||
|
const metadata = {
|
||||||
|
// added to overcome missing value in auth0 .well-known/openid-configuration
|
||||||
|
// see: https://github.com/IdentityModel/oidc-client-js/issues/1067
|
||||||
|
// see: https://github.com/IdentityModel/oidc-client-js/pull/1068
|
||||||
|
end_session_endpoint: `process.env.OIDC_ISSUER/v2/logout?client_id=process.env.OIDC_CLIENT_ID`,
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<OidcContext
|
<OidcContext
|
||||||
issuer="https://dev-hvw40i79.auth0.com"
|
issuer="https://dev-hvw40i79.auth0.com"
|
||||||
client_id="aOijZt2ug6Ovgzp0HXdF23B6zxwA6PaP"
|
client_id="aOijZt2ug6Ovgzp0HXdF23B6zxwA6PaP"
|
||||||
redirect_uri="https://darrelopry.com/svelte-oidc/"
|
redirect_uri="https://darrelopry.com/svelte-oidc/"
|
||||||
post_logout_redirect_uri="https://darrelopry.com/svelte-oidc/">
|
post_logout_redirect_uri="https://darrelopry.com/svelte-oidc/"
|
||||||
|
metdata={metadata}
|
||||||
|
>
|
||||||
|
|
||||||
<button on:click|preventDefault='{() => login() }'>Login</button>
|
<button on:click|preventDefault='{() => login() }'>Login</button>
|
||||||
<button on:click|preventDefault='{() => logout() }'>Logout</button><br />
|
<button on:click|preventDefault='{() => logout() }'>Logout</button><br />
|
||||||
<pre>isLoading: {$isLoading}</pre>
|
<pre>isLoading: {$isLoading}</pre>
|
||||||
<pre>isAuthenticated: {$isAuthenticated}</pre>
|
<pre>isAuthenticated: {$isAuthenticated}</pre>
|
||||||
<pre>authToken: {$authToken}</pre>
|
<pre>authToken: {$accessToken}</pre>
|
||||||
<pre>idToken: {$authToken}</pre>
|
<pre>idToken: {$idToken}</pre>
|
||||||
<pre>userInfo: {JSON.stringify($userInfo, null, 2)}</pre>
|
<pre>userInfo: {JSON.stringify($userInfo, null, 2)}</pre>
|
||||||
<pre>authError: {$authError}</pre>
|
<pre>authError: {$authError}</pre>
|
||||||
</OidcContext>
|
</OidcContext>
|
||||||
|
|
@ -59,6 +68,7 @@ import {
|
||||||
* client_id - OAuth ClientId
|
* client_id - OAuth ClientId
|
||||||
* redirect_uri - default: window.location.href
|
* redirect_uri - default: window.location.href
|
||||||
* post_logout_redirect_uri - override the default url that OIDC will redirect to after logout. default: window.location.href
|
* post_logout_redirect_uri - override the default url that OIDC will redirect to after logout. default: window.location.href
|
||||||
|
* metadata - set default metadata or metadata missing from authority.
|
||||||
|
|
||||||
### Functions
|
### Functions
|
||||||
* login(preseveRoute = true, callback_url = null) - begin a user login.
|
* login(preseveRoute = true, callback_url = null) - begin a user login.
|
||||||
|
|
@ -68,12 +78,13 @@ import {
|
||||||
### Stores
|
### Stores
|
||||||
* isLoading - if true OIDC Context is still loading.
|
* isLoading - if true OIDC Context is still loading.
|
||||||
* isAuthenticated - true if user is currently authenticated
|
* isAuthenticated - true if user is currently authenticated
|
||||||
* authToken - api token
|
* accessToken - access token for connecting to apis.
|
||||||
* userInfo - the currently logged in user's info from OIDC
|
* idToken - identity token for getting user info easily.
|
||||||
|
* userInfo - the currently logged in user's info from OIDC userInfo endpoint
|
||||||
* authError - the last authentication error.
|
* authError - the last authentication error.
|
||||||
|
|
||||||
### Constants
|
### Constants
|
||||||
* OIDC_CONTEXT_CALLBACK_URL,
|
* OIDC_CONTEXT_CALLBACK_URL
|
||||||
* OIDC_CONTEXT_CLIENT_PROMISE - key for the OIDC client in setContext/getContext.
|
* OIDC_CONTEXT_CLIENT_PROMISE - key for the OIDC client in setContext/getContext.
|
||||||
* OIDC_CONTEXT_LOGOUT_URL,
|
* OIDC_CONTEXT_LOGOUT_URL,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ import {
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td>isLoading</td><td>{$isLoading}</td></tr>
|
<tr><td>isLoading</td><td>{$isLoading}</td></tr>
|
||||||
<tr><td>isAuthenticated</td><td>{$isAuthenticated}</td></tr>
|
<tr><td>isAuthenticated</td><td>{$isAuthenticated}</td></tr>
|
||||||
<tr><td>accessToken</td><td>{$accessToken}</td></tr>
|
<tr><td>accessToken</td><td style="word-break: break-all;">{$accessToken}</td></tr>
|
||||||
<tr><td>idToken</td><td style="word-break: break-all;">{$idToken}</td></tr>
|
<tr><td>idToken</td><td style="word-break: break-all;">{$idToken}</td></tr>
|
||||||
<tr><td>userInfo</td><td><Highlight language={json} code={JSON.stringify($userInfo, null, 2) || ''} /></td></tr>
|
<tr><td>userInfo</td><td><Highlight language={json} code={JSON.stringify($userInfo, null, 2) || ''} /></td></tr>
|
||||||
<tr><td>authError</td><td>{$authError}</td></tr>
|
<tr><td>authError</td><td>{$authError}</td></tr>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
isLoading,
|
isLoading,
|
||||||
authError,
|
authError,
|
||||||
userInfo
|
userInfo,
|
||||||
} from './oidc';
|
} from './oidc';
|
||||||
|
|
||||||
// props.
|
// props.
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ export async function login(preserveRoute = true, callback_url = null) {
|
||||||
* @param {string} logout_url - specify the url to return to after login.
|
* @param {string} logout_url - specify the url to return to after login.
|
||||||
*/
|
*/
|
||||||
export async function logout(logout_url = null) {
|
export async function logout(logout_url = null) {
|
||||||
// getContext(OIDC_CONTEXT_CLIENT_PROMISE) returns a promise.
|
|
||||||
const oidc = await getContext(OIDC_CONTEXT_CLIENT_PROMISE)
|
const oidc = await getContext(OIDC_CONTEXT_CLIENT_PROMISE)
|
||||||
const returnTo = logout_url || getContext(OIDC_CONTEXT_POST_LOGOUT_REDIRECT_URI) || window.location.href;
|
const returnTo = logout_url || getContext(OIDC_CONTEXT_POST_LOGOUT_REDIRECT_URI) || window.location.href;
|
||||||
accessToken.set('');
|
accessToken.set('');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue