🌺 So I woke up last night thinking "This might be a bit weird." 🌺
Article
I want to walk through what I did and why. So this article will go over integrating my existing app with sample code generated by creating the API on the platform.
My Cloud Foundry application is Node with Express framework routing, .ejs view engine. This API called App ID
has a user registry that comes with sample code | SDKs for Swift, Node, Java and Android. The API has a free tier for up to 1000 users and 1000 events (an 'event' being like someone logging in).
Best way to see all features of the app is the API Docs.
Friday Night
I was on my beanbag in my office using Passport-Local Mongoose for a quick login by email and password for this application.
Do I really need to store user information in MongoDB?
Nobody will need to sign-up for this application.
Currently, I am giving out the link to the application for a small pool of people that it could help. The application serves one purpose and zero APIs are used in it. Nothing sensitive really.
Since I was using Passport.js already, I faintly recalled that there was a service on IBM Cloud I might've seen that used Passport somehow - this API ended up being App ID. It has a Node SDK for mobile and web.
I was looking into the App ID documentation, and took note of something that might be really helpful: The Cloud Directory.
So, I decided to use this API to register my users for my application.
And this move saved me a heck of a lot of time on Friday evening.
Weird part is that I have to populate the passwords for users...
Time Spent - My First Time Using This API
Let's get into it. Here are the steps. Shouldn't take much.
📄 Register for IBM Cloud
📧 Confirm Registration by email
💻 Login to Account
😄 Configure IBM Cloud CLI
🎸 Create App ID Service
🎨 Download Sample Code
🌊 Integrate to Existing App
👽 Setup and Redirect from Login
🎀 Add users in Cloud Directory
👑 Deploy Application
Register
Does not require anything but name | email. No cards.
Confirmation
I did this sign up process in writing this to make sure I go through everything, took less than five minutes to get the confirmation email per registering to the platform.
Login
Login to your account.
CLI
You will need this command line interface for IBM Cloud. This is for when you build locally and then want to re-deploy the sample code with regards to this tutorial.
Commands that you need to know (remember post-install to have a new terminal session to start using the CLI) =>
ibmcloud login
ibmcloud target --cf
API
Create the API for your own use. You can use my link or find App ID under the Security section of the Catalog. You can do this all by the IBM Cloud CLI.
Click
Once you reach the landing page for the service, there is a little button labeled 'Create' in furthest right-hand corner. Click that to create an instance of App ID for your own use.
Sample Code
Download the sample code for Swift, Node, Java or Android.
Integrate
You can use this service while hosting your application on other platforms. It does not have to be hosted on IBM Cloud.
Remember that sample code? It is really useful here.
I opened the /protected.ejs in Sublime and placed the code of my existing application's home page here.
Then I made sure all the paths to the files were correct so it renders properly.
Setup
For when you want to re-deploy this sample application to IBM Cloud with your integrations made, you will need to look at the alias connection for the sample code that is at the bottom of the manifest.yml
.
This alias creates a connection between your App ID service and the sample code being a Cloud Foundry application. So, the IBM Cloud CLI needs to be configured for you to do this. The documentation on this part is actually very good.
BUT there is one funky thing to deal with that will save you some time.
If you look in your account's Resource List
in the side panel:
Are there whitespaces in your service name? Upon re-deployment, having whitespace will mess things up. If your service name for App ID has whitespace, for example App ID-4343
then use the ellipsis on the right to Rename
it to AppID-4343
to correct this.
Then go to your sample code locally and look at your manifest.yml file. Does the service name with the word alias
in it have any whitespace?
Lets go take off that empty space that will only make for errors in our terminal, who has always been by our side!
Then follow the commands here and create that alias properly to bind to that service name. It should not spit out any errors now.
And one small note - this particular command in those instructions?
ibmcloud resource service-alias-create {ALIAS_NAME} --instance-name {SERVICE_INSTANCE_NAME}
You can take off those curly brackets when you make this command for those names.
And if you mess up, you can delete the alias. To do this - you go into your IBM Cloud "Resource List" in your left-side navigation bar, find the instance of App ID with the word "alias" in the title of the service, click the ellipsis and select "Delete" in the drop-down.
Redirect
The manifest.yml is necessary for deploying the app with your modifications from the command line. You can read about its purpose in regards to the platform in the Cloud Foundry documentation if you would like to know more.
Lets go back to the App ID service home page on IBM Cloud.
We need to add the proper callback for your application.
Click on Manage Authentication
in the service navigation bar.
And open the Authentication Settings
tab.
Look at your application's name in the manifest.yml file. What is your domain name?
Right now you probably have not routed this to being a custom domain, so let's use the mybluemix.net
domain and add /ibm/bluemix/appid/callback
to the end of that.
You can add any other paths here too. In full, you are providing here the nameofyourapp.mybluemix.net/ibm/bluemix/appid/callback
for that kosher callback.
Cloud Directory
Finally, now we can populate your Cloud Directory with users!
Make sure that your Cloud Directory is toggled On
within the Identity Providers
tab of the Manage Authentication
management section.
And add your users within the Users
section!
Live
Once you are ready to have a live link by configuration across these above steps, you can go into the root directory locally for your sample code app. Type the command ibmcloud app push
to trigger the deployment of your application.
This process will give you a link to the live application when the deployment process has completed.
Try logging in with one of the emails/usernames to test it out.
There are a ton of great features to this service. Remember, you don't have to link your credit card here to make the service. But it will stop functioning per the 1000 free events occurring.
I think this threshold would be the first upper limit hit unless you can add multiple users in a batch by the API. This is due to my testing the login making for 6 events in itself. But for a demo | PoC or the secure login of an app with light amounts of web traffic, this is a possible temporary free solution.
Hope you liked this tutorial. Thanks!
Some Helpful Links
Top comments (0)