Welcome to this series of hands on
tutorials from the SAP HANA Academy I'm Philip Mugglestone
in this series. We're covering SAP Graph
in this video tutorial,
we're gonna see how we can deploy an application as a developer
that accesses SAP Graph but deploy that completely outside of the SAP world.
We're actually going to deploy it to elastic beanstalk on Amazon Web Services
so obviously you'll need to have an AWS account
and of course the approach is going to be very similar
for whatever place you might want to host your application.
Now,
I've got an example application so if we go to the GitHub of the SAP HANA Academy
github.com/saphanaacademy and then go to repositories and you can search on
graph-app
and we can find a repo here. Now it's up to you.
What you can do is clone it or you can download it.
I've not got git actually installed on this machine here,
so I'm just gonna download the zip of course you can clone it.
So I'm gonna go
into my downloads folder
where you can see we've got the graph-app and I'm going to extract it.
So now I can see I've got a folder with some files Now
the files that actually really need here is going to be auth.js, graph.js
the package.json and the server.js just four files are going to be needed.
So I'm gonna copy those
and I'm gonna go to my documents
or maybe make a new folder
and I'll paste those files in.
So then we maybe want to look at those files from Visual studio code
so now we can see, we've got a Node.js application, a simple application.
We've gotta package.json just using express basically. And a few other things
we've got server.js
this is the main application that will run basically,
it's going to be using express and it's got a little health check, URL it's got
calls to graph.js and auth.js. We'll see in a moment
basically it's got some endpoints basically just a very simple
self enclosed application which is enabling you to access different
services of SAP Graph including going to look at sales quotes
which should be coming from SAP Sales Cloud in our case
it's pretty straightforward, we've seen this in previous video tutorials,
the graph.js this is basically what's going to make the calls out to SAP Graph.
So it's going to be using node fetch to make the requests.
So you see it's here constructing the different URL s based on what's been set
and it's gonna be passing the correct levels of authentication,
authorization in in many cases using a token.
Now it's very important that you bear in mind we've seen this previously many times,
there are different approaches from a client application
in this example,
I'm going to take the approach of doing a
user so we can actually propagate a user through
to the back end LoB systems based on the email so we need to pass that user identity.
So we need the jwt token of that.
So this code will allow you to do that basically out of the box.
And in terms of that authentication,
it's auth.js that actually has the code that allows you to see
that you can see it's set up to use this user approach by default
defines called back URL etcetera
and it's going to set a cookie in the
application which has got the user token etcetera.
But it's just one very simple example of how it might work.
And here you can see the actual code that does the authorization.
It will do a headless approach
with client credentials that's fairly straightforward but
we're going to show it actually working with the authorization code approach.
You can see all the code in this example
will allow you to actually go ahead
and make the calls to SAP Graph to get authenticated properly.
So what we're going to need to do is to basically zip this up so we
can actually then deploy it to elastic beanstalk
So let's go again back to our folder.
And what we'll do is we will zip it up.
So let's compress it, we can call it
and now we're ready to go to
AWS and actually deploy it. Now.
Typically you're gonna want to be using your
own domain when you're deploying application here.
So let's just go and see how that can be set up.
So let's just go to route 53 which is
one way that you can define your own custom domains
and we'll see that we've got a hosted zone
and it's partnerengineering.info and we can see we've basically
.partnerengineering.info create an application.
So maybe we want graph-app.partnerengineering.info to do that.
We'll need to go to the certificate manager.
Let's go to the certificate Manager.
Of course,
this is the Amazon Web Services way of doing it completely up
to you how you would want to do that.
But what we'll need to do is request a certificate
and what we're going to want to have is graph-app.partnerengineering.info
We'll use DNS validation
and request
and we can see that the certificate has been issued. We've now got a certificate I. D
you might have some additional steps in naturally doing that.
So now we can go back to elastic beanstalk and we
can create our application so we can use the wizard here,
we can have a name for our app, call it graph app
and then we need to say what platform?
Well it's a Node.js application so let's choose Node.js Okay,
Node.js 14 will be just fine for us
and then we're gonna upload our code
so there we can say local file,
choose our file and that's where we go to the
zip file that we just created.
And now before we finish we're gonna configure some more options.
So the first thing we'll do is just change it to being high availability
and that means we can now configure a load balancer.
So let's go ahead and hit edit on the load balancer
and we're going to add a listener
because we're gonna be using https here.
So we're gonna say port 443
protocol https
and we're gonna choose our certificate that we've just created
and then we can hit add,
make sure that https is enabled a new don't need to enable http, you can disable that.
And then we're going to go to processes and we're going to select the default one
and we're going to edit it
and then we're going to set the health check path.
So specifically the path and we actually called it
health as the end point.
That way the health check will run but it won't
actually need to be fully authenticated as a user.
Otherwise that will cause us some challenges.
So now we can hit save on that. Now we can save the load balancer
and now we can go up to software
and edit that.
And this is where we can set environment properties, effectively,
environment variables.
And that's where we will need to set them.
And actually the easy way to do that
is to go to the downloads folder where we've got a .env file
and I'll just open that up in visual studio code
and now we know the names and some of the values we can set.
So for example we'll set the debug option
a set of value.
Then we're going to have
the auth type, we'll set it to user
we're gonna want our SAP Graph URL Remember that information is available from
your key user or from your administrator in the creds file,
let's just open that one up. We've got the URL here.
We're also going to want to have the graph I. D.
The defaults v1 and that's the one we happen to be using the graph. ID
v1
we're gonna want the token URL
so that's the URL in the UAA section
and we're gonna want to have our client id and client secret
we're gonna make sure we get the name of the environment variable correct?
So that's the client I. D.
To copy the value
and also the client secret.
So now we've got all of our environment variables that we need. We can hit save
and now we're done with the configuration we can go ahead and hit create app
and it will take a few minutes for that to complete
so we can see that the deployment is now finished.
You can see it's up and running and we've got an environment created graph app dash. M
now before we can actually test it we just need to configure a couple of other things.
So let's go back to route 53 because we've got to configure the domain name.
Let's go to our domain partnerengineering.info And what
we're going to do is manage the DNS
select partnerengineering.info
and now we're going to create a record so what we're going to create is graph-app,
.partnerengineering.info it's going to be an A
type record and we're gonna select alias
and then we're gonna choose where we want it to
go to so we're gonna go to elastic beanstalk,
we'll choose our region
and we'll choose our environment. Now we can see the one we've just created
and that would create records
so that's now been done
and we can see we've got our
graph-app.partnerengineering.info that maps to our application.
So now we should be able to go ahead and launch
our application so let's go and put in graph-app.
partnerengineering.info
and notice we get an error saying invalid. Redirect
and that's because it's trying to now access graph this makes sense because graph
is actually protecting when you want to do a user based authentication so what
we need to do and this is something that the administrator for SAP Graph will
do for you is actually add this to the allow list to add this URL
So let's copy that
and we'll go now as the administrator personnel,
what we can do is go to our instance and subscriptions in
the sub account where we've got our graph service instance here it is
and we're going to update it
and we're gonna need to put some JSON into add the new
call back into the allow list now seen previous video tutorials.
Typically what the administrator would do is that they've
got a file with the current instance parameters.
So I'm going to open that and then I'm gonna just simply add this
new one in double quotes to the redirect URI basically this will now enable that
for our system. So let's go ahead and save that.
We're gonna copy that value as the administrator and now paste that in
here so that I can then update my instance
and now if we go back to our application and we try to launch it again,
we can see the app now runs were allowed to
access it and if we try and access the services
were actually talking to SAP Graph from Amazon Web Services we can see
that we've got the different entities for the sap.graph workspace.
If you want to access actual data we can see we can see
these sales quotes and it's now reaching
right through to the SAP Sales Cloud system
and actually
doing queries - getting us information back out
from this system.
So it's basically using this approach where we take the logged in user and that gets
passed all the way through to the back end system based on having the same email.
So we've seen the whole process.
So in this video tutorial we've seen how
we can deploy an application that's working with
SAP Graph outside of the SAP world actually in
Amazon Web Services elastic beanstalk we've done a custom domain
and we've got all the user authentication set up correctly.
So you can go right into the back end
systems without requiring any kind of technical user,
basically using identity propagation.
You can find more video tutorials on our Youtube channel
if you'd like to be informed as soon as new video tutorials are published,
then please subscribe.
Thanks for watching.