Forum Stats

  • 3,874,157 Users
  • 2,266,675 Discussions
  • 7,911,745 Comments

Discussions

Creating login and authentication in jet 12 project

user525840
user525840 Member Posts: 15 Blue Ribbon
edited Aug 29, 2022 10:40AM in Oracle JET

Hello experts,

I am using oracle jet version 12 quick start nav drawer template for my project.

Now I wish to implement login page and authentication mechanism either using google , OAuth or anything else.

I searched for login on this forum and i came across many related posts but they were of 2017 year which uses oj.router based on jet version 3+ . My jet version is 12 so the same solution does not work for me.


Can anyone help guide implementing the same for latest version or divert to specific documentation please?

Regards,

Yogesh

Tagged:

Best Answer

  • Philip Sommer
    Philip Sommer Member Posts: 118 Bronze Badge
    Answer ✓

    Hi Yogesh,


    Take a look at the Cookbook example for the router at https://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=corerouter&demo=module

    Setting up the new router should be fairly similar to the old one.

    I implemented the login screen in my application as follows. (Don't know if this is best practise, but it works.) This is also very similar to the router example above.

    1. Create a oj-module element in your main/index HTML to switch between login and content screens/modules.
    2. During application startup - e.g. in your root viewmodel constructor - configure the router paths for login and content. Default should be login.
    3. Check the login status of the user. If login is valid, directly navigate to content; Else stay on the login page.
    4. (Optional) If you have more than one content-screen/module you may want to return your user to the one he last visited (if the login is still valid). In this case, I made a simple extension to the OJ CoreRouter which keeps track of the last routing state in the SessionStorage. I then simply restore the cached state.



    Obviously, you will need to change this for the GoogleAPI, e.g. the validateToken() call would need to be replaced/changed.


    Kind Regards,

    Philip

Answers

  • Philip Sommer
    Philip Sommer Member Posts: 118 Bronze Badge
    Answer ✓

    Hi Yogesh,


    Take a look at the Cookbook example for the router at https://www.oracle.com/webfolder/technetwork/jet/jetCookbook.html?component=corerouter&demo=module

    Setting up the new router should be fairly similar to the old one.

    I implemented the login screen in my application as follows. (Don't know if this is best practise, but it works.) This is also very similar to the router example above.

    1. Create a oj-module element in your main/index HTML to switch between login and content screens/modules.
    2. During application startup - e.g. in your root viewmodel constructor - configure the router paths for login and content. Default should be login.
    3. Check the login status of the user. If login is valid, directly navigate to content; Else stay on the login page.
    4. (Optional) If you have more than one content-screen/module you may want to return your user to the one he last visited (if the login is still valid). In this case, I made a simple extension to the OJ CoreRouter which keeps track of the last routing state in the SessionStorage. I then simply restore the cached state.



    Obviously, you will need to change this for the GoogleAPI, e.g. the validateToken() call would need to be replaced/changed.


    Kind Regards,

    Philip

  • As usual, Philip is correct. The CoreRouter is not that much different from the older ojRouter, and the methods used for actual Login integration are the same.

  • user525840
    user525840 Member Posts: 15 Blue Ribbon

    Thank you John and Philip.

    I will try to implement this logic in my application.