# Logging in using passport strategy works, but redirects me back to login page

**URL:** <https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214>\
**Category:** General\
**Created:** [20 April 2020 21:33 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214 "2020-04-20T21:33:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![justAnotherDev](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@justAnotherDev](https://discourse.nodered.org/u/justAnotherDev)\
**Post date:** [20 April 2020 21:33 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/1 "2020-04-20T21:33:53Z")

</div>

I am using [`passport-okta-oauth`](http://www.passportjs.org/packages/passport-okta-oauth/) to login to my Node RED instance and have confirmed that the login is succeeding (by logging to the console the `profile` object inside of of the `verify` callback), however after redirecting back to my instance it reloads the homepage with "Sign in using Okta" still visible instead of to the dashboard.

It seems I must be missing a final step, but can't figure it out. Here is my code:

```auto
adminAuth: {
    type:"strategy",
    strategy: {
        name: "okta",
        label: "Sign in using Okta",
        icon:"fa-key",
        strategy: require("passport-okta-oauth").Strategy,
        options: {
            audience: "https://mycompany.okta.com",
            clientID: "XXXXXXX",
            clientSecret: "xxxxxx",
            scope: ["openid", "email", "profile", "offline_access"],
            response_type: "code",
            callbackURL: "https://mycompany.com/auth/strategy/callback",

            verify: function(accessToken, refreshToken, profile, done) {
                console.log(profile);
                return profile;
            }
        }
    },
    users: [
        { username: "justAnotherDev", permissions: ["*"] }
    ]
},

```

The console prints out the signed in profile object:

```auto
{ provider: 'okta',
  id: 'xxxxxxxx',
  displayName: 'justAnotherDev',
  username: 'justAnotherDev@mycompany.com',
  name:
   { fullName: 'justAnotherDev',
  emails: [{ value: 'justAnotherDev@mycompany.com' }],
  _raw:
   '{"sub":"xxxxxxxx","name":"justAnotherDev","locale":"US","email":"justAnotherDev@mycompany.com","updated_at":1587413637,"email_verified":true}',
  _json:
   { sub: 'xxxxxxxx',
     name: 'justAnotherDev',
     locale: 'US',
     email: 'justAnotherDev@mycompany.com',
     nickname: 'justAnotherDev',
     preferred_username: 'justAnotherDev@mycompany.com',
     zoneinfo: 'America/Los_Angeles',
     updated_at: 1587413637,
     email_verified: true } }

```

What am I missing? I have tried adding `done(null, profile);` before (and in place of) returning the profile object but that didn't help either.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 April 2020 22:02 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/2 "2020-04-20T22:02:06Z")

</div>

> [@justAnotherDev](#):
>
> ```auto
> verify: function(accessToken, refreshToken, profile, done) {
> console.log(profile);
> return profile;
> }
> 
> ```

Comparing with our [GitHub auth plugin](https://github.com/node-red/node-red-auth-github/blob/4fe9d738c4e65c88b9a05d40e780c1f3479fd98c/lib/index.js#L50), you should definitely have `done(null,profile)` and not the `return` statement.

Beyond that, I can't see anything missing.

You should edit your settings file to enable the `audit` logging events - that may give you a bit more of a hint where its failing.

---

<div class="post-metadata">

**Author:** ![justAnotherDev](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@justAnotherDev](https://discourse.nodered.org/u/justAnotherDev)\
**Post date:** [21 April 2020 01:27 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/3 "2020-04-21T01:27:05Z")

</div>

`done(null, profile);` doesn't seem to help. Adding the audit call does at least display this error in the log:

```auto
21 Apr 01:20:28 - [audit] {"event":"auth.login.fail.oauth","username":"justAnotherDev@mycompany.com","level":98,"timestamp":1587432028295}
21 Apr 01:20:29 - [audit] {"event":"auth.invalid-token","level":98,"timestamp":1587432029075}

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 April 2020 09:24 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/4 "2020-04-21T09:24:06Z")

</div>

The audit log shows it has tried to authenticate the username `justAnotherDev@mycompany.com`, but in your `users` array, your user is called `justAnotherDev`.

---

<div class="post-metadata">

**Author:** ![justAnotherDev](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@justAnotherDev](https://discourse.nodered.org/u/justAnotherDev)\
**Post date:** [21 April 2020 19:11 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/5 "2020-04-21T19:11:47Z")

</div>

That was it! It is probably worth adding a note to the [documentation](https://nodered.org/docs/user-guide/runtime/securing-node-red#oauthopenid-based-authentication) that values provided for `username` may need to be an email, and ideally update the error message.

Thanks so much for helping me solve this so quickly!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 May 2020 19:11 UTC](https://discourse.nodered.org/t/logging-in-using-passport-strategy-works-but-redirects-me-back-to-login-page/25214/6 "2020-05-05T19:11:57Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
