Get Token 1
parent
c6068da403
commit
408bbb82ba
File diff suppressed because one or more lines are too long
|
|
@ -23,7 +23,9 @@
|
|||
"@nestjs/common": "^11.0.1",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"axios": "^1.8.4",
|
||||
"class-validator": "^0.14.1",
|
||||
"glob": "7.2.3",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,9 +17,15 @@ importers:
|
|||
'@nestjs/platform-express':
|
||||
specifier: ^11.0.1
|
||||
version: 11.0.11(@nestjs/common@11.0.11(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.0.11)
|
||||
axios:
|
||||
specifier: ^1.8.4
|
||||
version: 1.8.4
|
||||
class-validator:
|
||||
specifier: ^0.14.1
|
||||
version: 0.14.1
|
||||
glob:
|
||||
specifier: 7.2.3
|
||||
version: 7.2.3
|
||||
reflect-metadata:
|
||||
specifier: ^0.2.2
|
||||
version: 0.2.2
|
||||
|
|
@ -1427,6 +1433,9 @@ packages:
|
|||
asynckit@0.4.0:
|
||||
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
|
||||
|
||||
axios@1.8.4:
|
||||
resolution: {integrity: sha512-eBSYY4Y68NNlHbHBMdeDmKNtDgXWhQsJcGqzO3iLUM0GraQFSS9cVgPX5I9b3lbdFKyYoAEGAZF1DwhTaljNAw==}
|
||||
|
||||
b4a@1.6.7:
|
||||
resolution: {integrity: sha512-OnAYlL5b7LEkALw87fUVafQw5rVR9RjwGd4KUwNQ6DrrNmaVaUCgLipfVlzrPQ4tWOR9P0IXGNOx50jYCCdSJg==}
|
||||
|
||||
|
|
@ -2073,6 +2082,15 @@ packages:
|
|||
flatted@3.3.3:
|
||||
resolution: {integrity: sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==}
|
||||
|
||||
follow-redirects@1.15.9:
|
||||
resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==}
|
||||
engines: {node: '>=4.0'}
|
||||
peerDependencies:
|
||||
debug: '*'
|
||||
peerDependenciesMeta:
|
||||
debug:
|
||||
optional: true
|
||||
|
||||
foreground-child@3.3.1:
|
||||
resolution: {integrity: sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==}
|
||||
engines: {node: '>=14'}
|
||||
|
|
@ -2946,6 +2964,9 @@ packages:
|
|||
resolution: {integrity: sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==}
|
||||
engines: {node: '>= 0.10'}
|
||||
|
||||
proxy-from-env@1.1.0:
|
||||
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
|
||||
|
||||
punycode@2.3.1:
|
||||
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
|
||||
engines: {node: '>=6'}
|
||||
|
|
@ -5049,6 +5070,14 @@ snapshots:
|
|||
|
||||
asynckit@0.4.0: {}
|
||||
|
||||
axios@1.8.4:
|
||||
dependencies:
|
||||
follow-redirects: 1.15.9
|
||||
form-data: 4.0.2
|
||||
proxy-from-env: 1.1.0
|
||||
transitivePeerDependencies:
|
||||
- debug
|
||||
|
||||
b4a@1.6.7: {}
|
||||
|
||||
babel-jest@29.7.0(@babel/core@7.26.9):
|
||||
|
|
@ -5775,6 +5804,8 @@ snapshots:
|
|||
|
||||
flatted@3.3.3: {}
|
||||
|
||||
follow-redirects@1.15.9: {}
|
||||
|
||||
foreground-child@3.3.1:
|
||||
dependencies:
|
||||
cross-spawn: 7.0.6
|
||||
|
|
@ -6754,6 +6785,8 @@ snapshots:
|
|||
forwarded: 0.2.0
|
||||
ipaddr.js: 1.9.1
|
||||
|
||||
proxy-from-env@1.1.0: {}
|
||||
|
||||
punycode@2.3.1: {}
|
||||
|
||||
pure-rand@6.1.0: {}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,28 @@
|
|||
import { Controller, Get, Post } from '@nestjs/common';
|
||||
import { MufapiService } from './mufapi.service';
|
||||
|
||||
@Controller('mufapi')
|
||||
@Controller('api')
|
||||
export class MufapiController {
|
||||
constructor(private readonly mufapiService: MufapiService) {}
|
||||
|
||||
@Get()
|
||||
getHello() : String {
|
||||
return 'Hello popsa';
|
||||
async getHello() : Promise<string> {
|
||||
const user : string = "admin";
|
||||
const password : string = "admin";
|
||||
const conn : string = 'http://192.168.244.1/e-data-front/auth/login';
|
||||
const creds : string = '{"login":"' + user + '","password":"' + password + '"}';
|
||||
const options = {
|
||||
headers: {'Content-Type' : 'application/json'}
|
||||
};
|
||||
console.log(await this.mufapiService.getAccessToken(conn, creds, options));
|
||||
//return this.mufapiService.getAccessToken(conn, creds, options);
|
||||
return await this.mufapiService.getAccessToken(conn, creds, options);
|
||||
}
|
||||
|
||||
@Post('menu')
|
||||
getMenu () : JSON {
|
||||
let menu : JSON = JSON.parse('{"id": 2}');
|
||||
return menu;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,32 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { error } from 'console';
|
||||
import { response } from 'express';
|
||||
import { Interface } from 'readline';
|
||||
|
||||
@Injectable()
|
||||
export class MufapiService {}
|
||||
export class MufapiService {
|
||||
|
||||
async getAccessToken (path:string, body:string, headers) : Promise<string> {
|
||||
interface Token {
|
||||
access_token: string;
|
||||
};
|
||||
let token : Token;
|
||||
let ret : any = 'Error';
|
||||
await axios.post(path, body, headers).then((response)=>{
|
||||
token = response.data;
|
||||
//console.log(token);
|
||||
//console.log(token.access_token);
|
||||
ret = token.access_token;
|
||||
}).catch((error)=>{
|
||||
ret = error;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
getMenu () : string {
|
||||
return 'body';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue