forked from imodeljs/imodeljs-samples
-
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.
Use dummy sample showcase user for no-signin access. (imodeljs#11)
* Use dummy sample showcase user for no-signin access. * Add copyright notice for NoSignInIAuthClien.ts. * Pull from imjs_sample_showcase_user if exists, default to dev services API. * Set homepage to './' for relative sources. Buttons needs to also point to relative directory. * Add .nuspec for deployment.
- Loading branch information
Showing
5 changed files
with
96 additions
and
7 deletions.
There are no files selected for viewing
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,18 @@ | ||
<?xml version="1.0"?> | ||
<package > | ||
<metadata> | ||
<id>iModeljsSampleShowcase</id> | ||
<version>$version$</version> | ||
<title>iModeljs Samples Showcase</title> | ||
<authors>IMSS Dev</authors> | ||
<owners>IMSS Dev</owners> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>iModeljs Samples Showcase</description> | ||
<releaseNotes></releaseNotes> | ||
<copyright>Copyright 2020</copyright> | ||
<tags></tags> | ||
</metadata> | ||
<files> | ||
<file src="build\**" target="content\sample-showcase" /> | ||
</files> | ||
</package> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { AuthStatus, BeEvent, BentleyError, ClientRequestContext } from "@bentley/bentleyjs-core"; | ||
import { AccessToken } from "@bentley/itwin-client"; | ||
import { FrontendAuthorizationClient } from "@bentley/frontend-authorization-client"; | ||
|
||
export class NoSignInIAuthClient implements FrontendAuthorizationClient { | ||
public readonly onUserStateChanged: BeEvent<(token: AccessToken | undefined) => void>; | ||
protected _accessToken?: AccessToken; | ||
|
||
constructor() { | ||
this.onUserStateChanged = new BeEvent(); | ||
} | ||
|
||
public async signIn(requestContext?: ClientRequestContext): Promise<void> { | ||
if (requestContext) { | ||
requestContext.enter(); | ||
} | ||
await this.getAccessToken(); | ||
} | ||
public async signOut(requestContext?: ClientRequestContext): Promise<void> { | ||
if (requestContext) { | ||
requestContext.enter(); | ||
} | ||
this._accessToken = undefined; | ||
} | ||
|
||
public get isAuthorized(): boolean { | ||
return this.hasSignedIn; | ||
} | ||
|
||
public get hasExpired(): boolean { | ||
return !this._accessToken; | ||
} | ||
|
||
public get hasSignedIn(): boolean { | ||
return !!this._accessToken; | ||
} | ||
|
||
public async generateTokenString(userURL: string, requestContext?: ClientRequestContext) { | ||
if (requestContext) { | ||
requestContext.enter(); | ||
} | ||
|
||
const response = await fetch(userURL); | ||
const tokenJson = { | ||
...await response.json(), | ||
_userInfo: { id: "MockId" }, | ||
}; | ||
this._accessToken = AccessToken.fromJson(tokenJson); | ||
} | ||
|
||
public async getAccessToken(): Promise<AccessToken> { | ||
if (!this._accessToken) | ||
throw new BentleyError(AuthStatus.Error, "Cannot get access token"); | ||
|
||
return this._accessToken; | ||
} | ||
} |
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