import ClientOAuth2 from "client-oauth2"
import opn from "open"
const oa = new ClientOAuth2({
authorizationUri: `${uaaUrl}/oauth/authorize`,
accessTokenUri: `${uaaUrl}/oauth/token`,
redirectUri, // a local webserver you set up in node
clientId,
clientSecret
})
// open the login page in a browser
opn(oa.code.getUri())
// wait until the local webserver is called
const url = (await callbackRequest).url
const token = await oa.code.getToken(url)
await got(url,{
headers:{ Authorization: `bearer ${token.accessToken}` } } )
const oauth = new ClientOAuth2({
authorizationUri: `${uaaUrl}/oauth/authorize`,
accessTokenUri: `${uaaUrl}/oauth/token`,
redirectUri: "http://localhost/notfound", // no need to set up a server here, will not be called
clientId,
clientSecret
})
const token = await oauth
.createToken(accessToken, refreshToken, tokenType, {})
.refresh()
.then(t => t.accessToken)
{
"abapfs.remote": {
"hanatrial": {
"url": "from_servicekey-url",
"username": "from_eclipse",
"password": "",
"client": "100",
"oauth": {
"clientId": "from_servicekey-uaa-clientId",
"clientSecret": "from_servicekey-uaa-clientSecret",
"loginUrl": "from_servicekey-uaa-url",
"saveCredentials": true
}
}
}
}
const headers = { Accept: "application/json" }
// get the list of available services
const sr = await got( "https://api.cf.eu10.hana.ondemand.com/v2/services",{ headers ,responseType: 'json'})
const services = sr.body
// get the endpoint configuration, to extract the login service URL
const resp = await got("https://api.cf.eu10.hana.ondemand.com", { headers ,responseType: 'json'})
const loginUrl = resp.body.links.login.href
// finally get the CF login token
const token = new ClientOAuth2({ accessTokenUri: `${loginUrl}/oauth/token` })
const findAbapTag = (tags: string[]) => tags && tags.find(t => t === "abapcp")
// find the service
const abapService = services.find(s => findAbapTag(s.entity.tags))
// find the first service instance
const abapServiceInstance = instances.find(
i => i.entity.service_guid === abapService?.metadata.guid
)
const headers = {
Authorization: `bearer ${token..accessToken}`,
Accept: "application/json"
}
const resp = await const resp = await got(`https://api.cf.eu10.hana.ondemand.com${abapServiceInstance.service_keys_url}`, {
headers,
searchParams: { q: `name:SAP_ADT` }, // Eclipse's. Should better use another
responseType: 'json'
})
const key =resp.body.data
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
50 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |