2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import { AuthPolicy, AuthToken } from "../models/authentication";
19 import { ExternalLoginProvider } from "../models/externalLoginProvider";
21 import { requestRest, formEncode, requestRestExt } from "./restService";
23 type AuthTokenResponse = {
30 class AuthenticationService {
31 public async getAvaliableExteralProvider() {
32 const result = await requestRest<ExternalLoginProvider[]>(`oauth/providers`, {
35 'Content-Type': 'application/x-www-form-urlencoded'
41 public async authenticateUserOAuth(email: string, password: string, scope: string): Promise<AuthToken | null> {
42 const result = await requestRest<AuthTokenResponse>(`oauth/login`, {
45 'Content-Type': 'application/x-www-form-urlencoded'
48 grant_type: "password",
58 access_token: result.access_token,
59 token_type: result.token_type,
60 expires: result.expires_at,
61 issued: result.issued_at
65 public async authenticateUserBasicAuth(email: string, password: string, scope: string): Promise<AuthToken | null> {
66 const result = await requestRest<string>(`rests/data/network-topology:network-topology/topology=topology-netconf?fields=node(node-id)`, {
69 'Authorization': "Basic " + btoa(email + ":" + password)
76 access_token: btoa(email + ":" + password),
78 expires: (new Date()).valueOf() / 1000 + 86400, // 1 day
79 issued: (new Date()).valueOf() / 1000
85 public async getAccessPolicies(){
86 return await requestRest<AuthPolicy[]>(`oauth/policies`, { method: "GET" }, true);
89 public async getServerReadyState(){
91 const result = await fetch("/ready", {method: "GET"});
92 return result.status == (200 || 304) ? true : false;
96 export const authenticationService = new AuthenticationService();
97 export default authenticationService;