-
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.
feat: add fixed issuers to authenticate component (#62)
* feat: moved models from uitransfer to shared * feat: moved services from uitransfer to shared * feat: moved auth components from uitransfer to shared * feat: added provider list above the webid component * fix: show components on correct machine state * fix: updated coverage * chore: center components in demo view Co-authored-by: Arne Vandoorslaer <[email protected]>
- Loading branch information
Showing
68 changed files
with
2,567 additions
and
79 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/dgt-components/demo/demo-authenticate.component.ts
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,43 @@ | ||
import { css, html, unsafeCSS } from 'lit-element'; | ||
import { RxLitElement } from 'rx-lit'; | ||
import { Theme } from '@digita-ai/dgt-theme'; | ||
import { SolidSDKService } from '../lib/services/solid-sdk.service' | ||
import { AuthenticateComponent } from '../lib/components/authentication/authenticate.component'; | ||
|
||
export class DemoAuthenticateComponent extends RxLitElement { | ||
private solidService = new SolidSDKService('UI Transfer'); | ||
|
||
onAuthenticated = (event: CustomEvent): void => { }; | ||
|
||
|
||
constructor() { | ||
super(); | ||
customElements.define('auth-flow', AuthenticateComponent); | ||
|
||
} | ||
/** | ||
* Renders the component as HTML. | ||
* | ||
* @returns The rendered HTML of the component. | ||
*/ | ||
render() { | ||
|
||
return html` | ||
<auth-flow .solidService="${this.solidService}" @authenticated="${this.onAuthenticated}"></auth-flow> | ||
`; | ||
|
||
} | ||
|
||
/** | ||
* The styles associated with the component. | ||
*/ | ||
static get styles() { | ||
|
||
return [ | ||
unsafeCSS(Theme), | ||
css``, | ||
]; | ||
|
||
} | ||
|
||
} |
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
115 changes: 115 additions & 0 deletions
115
packages/dgt-components/lib/components/authentication/authenticate.component.ts
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,115 @@ | ||
import { html, internalProperty, TemplateResult, property, PropertyValues, unsafeCSS, CSSResultArray, css } from 'lit-element'; | ||
import { createMachine, DoneEvent, interpret, Interpreter, State, StateMachine } from 'xstate'; | ||
import { RxLitElement } from 'rx-lit'; | ||
import { from } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { Theme } from '@digita-ai/dgt-theme'; | ||
import { SolidSDKService } from '../../services/solid-sdk.service'; | ||
import { Issuer } from '../../models/issuer.model'; | ||
import { ProviderListComponent } from '../provider/provider-list.component'; | ||
import { SeparatorComponent } from '../separator/separator.component'; | ||
import { LoadingComponent } from '../loading/loading.component'; | ||
import { WebIdComponent } from './webid.component'; | ||
import { AuthenticateContext, AuthenticateEvent, authenticateMachine, AuthenticateState, AuthenticateStates, AuthenticateStateSchema, SelectedIssuerEvent, WebIdEnteredEvent } from './authenticate.machine'; | ||
|
||
export class AuthenticateComponent extends RxLitElement { | ||
|
||
private actor: Interpreter<AuthenticateContext, AuthenticateStateSchema, AuthenticateEvent, AuthenticateState>; | ||
private machine: StateMachine<AuthenticateContext, AuthenticateStateSchema, AuthenticateEvent, AuthenticateState>; | ||
private predifinedIssuers: Issuer[] = [ | ||
{ description: 'Solid Community', icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAsVBMVEX///98Tf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KvjdXvos+sk5W/rePvEu00pctlbQ4q6b4hkoSS3GZxp7pJyPk6FBNvMp+I8IndTroLZkTBJLdZjAmZMvKRuqhVqIghch2KiTypVohQ5DoUE7LrSlzs+jyOQuxAzikNI+5q/zNKnXj9aPqos5atqDSrztkJsVUrqgFjKZerjsftHTf6vMVj9IfmOy0FDZX6yOFDmubavx1VuuNe2eXAeJXSb28JdLmOLn2lf1GNDnfyKIo9KIr0yf1FkAfwd03m24steT3OWvie79WrV69evXr16tWrV69evXr16tWrF6r/AA4sIsoKyfbTAAAAAElFTkSuQmCC', uri: 'https://solidcommunity.net' }, | ||
{ description: 'Inrupt', icon: 'https://inrupt.com/static/inrupt-social_0-372b94bf42bea86a81cc362e0c99d115.jpg', uri: 'https://inrupt.net/' }, | ||
]; | ||
|
||
@internalProperty() | ||
state?: State<AuthenticateContext>; | ||
|
||
@internalProperty() | ||
issuers?: Issuer[]; | ||
|
||
@property({ type: Object }) solidService: SolidSDKService; | ||
|
||
@property({ type: Boolean }) hideWebId = false; | ||
|
||
@property({ type: Boolean }) hideIssuers = false; | ||
|
||
constructor() { | ||
|
||
super(); | ||
|
||
this.define('provider-list', ProviderListComponent); | ||
this.define('webid-form', WebIdComponent); | ||
this.define('separator-component', SeparatorComponent); | ||
this.define('loading-component', LoadingComponent); | ||
|
||
} | ||
|
||
updated(changed: PropertyValues): void { | ||
|
||
super.updated(changed); | ||
|
||
if (changed.has('solidService')) { | ||
|
||
if (this.actor) this.actor.stop(); | ||
|
||
this.machine = createMachine(authenticateMachine(this.solidService)); | ||
|
||
// eslint-disable-next-line no-console | ||
this.actor = interpret(this.machine, { devTools: true }).onTransition((state) => console.log(state.value)); | ||
|
||
this.subscribe('state', from(this.actor)); | ||
this.subscribe('issuers', from(this.actor).pipe(map((state) => state.context.issuers))); | ||
|
||
this.actor.onDone((event: DoneEvent) => { this.dispatchEvent(new CustomEvent('authenticated', { detail: event.data.session })); }); | ||
|
||
this.actor.start(); | ||
|
||
} | ||
|
||
} | ||
|
||
onSubmit = (event: CustomEvent): void => { | ||
|
||
event.preventDefault(); | ||
this.actor.send(new WebIdEnteredEvent(event.detail)); | ||
|
||
}; | ||
|
||
onButtonCreateWebIDClick = (): void => { this.dispatchEvent(new CustomEvent('create-webid')); }; | ||
|
||
render(): TemplateResult { | ||
|
||
return html` | ||
${ this.state?.matches(AuthenticateStates.AWAITING_WEBID) ? html` | ||
${ !this.hideIssuers ? html`<provider-list @issuer-selected="${(event: CustomEvent) => this.actor.send(new SelectedIssuerEvent(event.detail))}" .providers="${this.predifinedIssuers}"></provider-list>` : html``} | ||
${ !this.hideWebId && !this.hideIssuers ? html`<separator-component>of</separator-component>` : html`` } | ||
${ !this.hideWebId ? html`<webid-form @submit-webid="${this.onSubmit}" @create-webid="${this.onButtonCreateWebIDClick}"></webid-form>` : html``} | ||
` : html` ${ this.state?.matches(AuthenticateStates.SELECTING_ISSUER) ? html` | ||
<provider-list @issuer-selected="${(event: CustomEvent) => this.actor.send(new SelectedIssuerEvent(event.detail))}" .providers="${this.issuers}"></provider-list>` | ||
: html`<loading-component></loading-component>` } | ||
`}`; | ||
|
||
} | ||
|
||
define(tag: string, module: CustomElementConstructor): void { | ||
|
||
if (!customElements.get(tag)) customElements.define(tag, module); | ||
|
||
} | ||
static get styles(): CSSResultArray { | ||
|
||
return [ | ||
unsafeCSS(Theme), | ||
css` | ||
separator-component { | ||
margin: var(--gap-large) 0; | ||
} | ||
`, | ||
]; | ||
|
||
} | ||
|
||
} | ||
|
||
export default AuthenticateComponent; |
Oops, something went wrong.