@equinor/fusion
Advanced tools
Comparing version 0.2.5 to 0.3.0
@@ -1,4 +0,4 @@ | ||
import AuthApp from "./AuthApp"; | ||
import AuthNonce from "./AuthNonce"; | ||
import AuthUser from "./AuthUser"; | ||
import AuthApp from './AuthApp'; | ||
import AuthNonce from './AuthNonce'; | ||
import AuthUser from './AuthUser'; | ||
export declare class FusionAuthAppNotFoundError extends Error { | ||
@@ -32,3 +32,3 @@ constructor(clientId: string); | ||
*/ | ||
login(clientId: string): void; | ||
loginAsync(clientId: string): Promise<void>; | ||
/** | ||
@@ -57,3 +57,3 @@ * Log out | ||
registerAppAsync(clientId: string, resources: string[]): Promise<boolean>; | ||
login(clientId: string): void; | ||
loginAsync(clientId: string): Promise<void>; | ||
logoutAsync(clientId?: string): Promise<void>; | ||
@@ -66,4 +66,4 @@ getCachedUserAsync(): Promise<AuthUser | null>; | ||
protected static getTokenFromHash(hash: string): string | null; | ||
protected buildLoginUrl(app: AuthApp, nonce: AuthNonce, customParams?: object): string; | ||
protected buildLoginUrlAsync(app: AuthApp, nonce: AuthNonce, customParams?: object): Promise<string>; | ||
protected resolveApp(resource: string): AuthApp | null; | ||
} |
@@ -1,7 +0,7 @@ | ||
import AuthApp from "./AuthApp"; | ||
import AuthToken from "./AuthToken"; | ||
import AuthNonce from "./AuthNonce"; | ||
import AuthCache from "./AuthCache"; | ||
import AuthUser from "./AuthUser"; | ||
import { trimTrailingSlash } from "../utils/url"; | ||
import AuthApp from './AuthApp'; | ||
import AuthToken from './AuthToken'; | ||
import AuthNonce from './AuthNonce'; | ||
import AuthCache from './AuthCache'; | ||
import AuthUser from './AuthUser'; | ||
import { trimTrailingSlash } from '../utils/url'; | ||
export class FusionAuthAppNotFoundError extends Error { | ||
@@ -38,3 +38,3 @@ constructor(clientId) { | ||
await this.updateTokenForAppAsync(app, token); | ||
window.location.hash = ""; | ||
window.location.hash = ''; | ||
} | ||
@@ -65,3 +65,3 @@ catch (e) { | ||
// For now this is not possible because of iframes and crazy stuff | ||
this.login(resource); | ||
await this.loginAsync(resource); | ||
return null; | ||
@@ -83,3 +83,3 @@ } | ||
} | ||
login(clientId) { | ||
async loginAsync(clientId) { | ||
const app = this.resolveApp(clientId); | ||
@@ -93,3 +93,3 @@ if (app === null) { | ||
// Get the top level window and redirect there | ||
getTopLevelWindow(window).location.href = this.buildLoginUrl(app, nonce); | ||
getTopLevelWindow(window).location.href = await this.buildLoginUrlAsync(app, nonce); | ||
} | ||
@@ -133,18 +133,21 @@ async logoutAsync(clientId) { | ||
catch (_a) { | ||
return ""; | ||
return ''; | ||
} | ||
} | ||
static getTokenFromHash(hash) { | ||
const parts = hash.substr(1).split("&"); | ||
const tokenPart = parts.find(part => part.indexOf("id_token=") === 0); | ||
if (typeof tokenPart === "undefined") { | ||
const parts = hash.substr(1).split('&'); | ||
const tokenPart = parts.find(part => part.indexOf('id_token=') === 0); | ||
if (typeof tokenPart === 'undefined') { | ||
return null; | ||
} | ||
return tokenPart.replace("id_token=", ""); | ||
return tokenPart.replace('id_token=', ''); | ||
} | ||
buildLoginUrl(app, nonce, customParams = {}) { | ||
const base = "https://login.microsoftonline.com/3aa4a235-b6e2-48d5-9195-7fcf05b459b0/oauth2/authorize"; | ||
const params = Object.assign({}, customParams, { client_id: app.clientId, response_type: "id_token", redirect_uri: getTopLevelWindow(window).location.href, domain_hint: "@equinor.com", nonce: nonce.getKey() }); | ||
const queryString = Object.keys(params).reduce((query, key) => query + `${query ? "&" : ""}${key}=${encodeURIComponent(params[key])}`, ""); | ||
return base + "?" + queryString; | ||
async buildLoginUrlAsync(app, nonce, customParams = {}) { | ||
const cachedUser = await this.getCachedUserAsync(); | ||
const base = 'https://login.microsoftonline.com/3aa4a235-b6e2-48d5-9195-7fcf05b459b0/oauth2/authorize'; | ||
const params = Object.assign({}, customParams, { client_id: app.clientId, response_type: 'id_token', redirect_uri: getTopLevelWindow(window).location.href, nonce: nonce.getKey(), login_hint: cachedUser ? cachedUser.upn : null }); | ||
const queryString = Object.keys(params) | ||
.filter(key => params[key]) | ||
.reduce((query, key) => query + `${query ? '&' : ''}${key}=${encodeURIComponent(params[key])}`, ''); | ||
return base + '?' + queryString; | ||
} | ||
@@ -156,3 +159,3 @@ resolveApp(resource) { | ||
app.clientId === resource); | ||
if (typeof app === "undefined") { | ||
if (typeof app === 'undefined') { | ||
return null; | ||
@@ -159,0 +162,0 @@ } |
@@ -8,5 +8,7 @@ import PersonRole from './PersonRole'; | ||
import PersonAccountType from './PersonAccountType'; | ||
export { PersonRole, PersonContract, PersonPosition, PersonProject, PersonBasePosition, PersonRoleScope, PersonAccountType, }; | ||
import PersonCompany from './PersonCompany'; | ||
export { PersonRole, PersonContract, PersonPosition, PersonProject, PersonBasePosition, PersonRoleScope, PersonAccountType, PersonCompany, }; | ||
declare type PersonDetails = { | ||
azureUniqueId: string; | ||
name: string; | ||
mail: string; | ||
@@ -19,3 +21,3 @@ jobTitle: string; | ||
accountType: PersonAccountType; | ||
company: string; | ||
company: PersonCompany; | ||
roles?: PersonRole[]; | ||
@@ -22,0 +24,0 @@ contracts?: PersonContract[]; |
@@ -24,3 +24,3 @@ export { IAuthContainer, default as AuthContainer } from './auth/AuthContainer'; | ||
export { default as Position, BasePosition, PositionInstance, AssignedPerson, PositionLocation, } from './http/apiClients/models/org/Position'; | ||
export { default as PersonDetails, PersonBasePosition, PersonContract, PersonPosition, PersonProject, PersonRole, PersonRoleScope, PersonAccountType, } from './http/apiClients/models/people/PersonDetails'; | ||
export { default as PersonDetails, PersonBasePosition, PersonContract, PersonPosition, PersonProject, PersonRole, PersonRoleScope, PersonAccountType, PersonCompany, } from './http/apiClients/models/people/PersonDetails'; | ||
export { createPagination, applyPagination, usePagination, useAsyncPagination, Page, Pagination, PagedResult, PaginationRange, } from './utils/Pagination'; | ||
@@ -27,0 +27,0 @@ export { useSorting, applySorting, SortDirection, PropertyAccessor, PropertyAccessorFunction, } from './hooks/useSorting'; |
{ | ||
"name": "@equinor/fusion", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "Everything a Fusion app needs to communicate with the core", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
179839
222
4327