Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

will this module work with Single page apps, and mobile iOS, android? #11

Open
surfjedi opened this issue Oct 12, 2014 · 27 comments
Open
Assignees
Labels

Comments

@surfjedi
Copy link

Does this support rest login and authenticating all requests for things like angular single page apps, iOS, android etc?

@projectxmaker
Copy link

@bajtos I am also trying to use loopback-passport for login of iOS and android app, and I have the same question as @surfjedi asked.

could you answer this question ?

@bajtos
Copy link
Member

bajtos commented Nov 12, 2014

I am not familiar with loopback-component-passport, please ask @raymondfeng, he is the person who wrote that module.

@benmarten
Copy link

I don't think handling login via native SDK and interaction via REST is supported (yet).
The way I handle it is via WebView. Point the user to e.g. /auth/Facebook in a UIWebView, then do sth. like this to get the data:

    - (void)webViewDidFinishLoad:(UIWebView *)webView
    {
        NSString *userId;
        NSString *accessToken;
        NSDate *createdDate;

        NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (NSHTTPCookie *cookie in [cookieJar cookies]) {
            if ([cookie.name isEqualToString:@"access_token"]) {
                accessToken = cookie.value;
                NSNumber *created = [cookie.properties objectForKey:@"Created"];
                createdDate = [NSDate dateWithTimeIntervalSinceReferenceDate:[created doubleValue]];
                [cookieJar deleteCookie:cookie];
            }
            else if ([cookie.name isEqualToString:@"userId"]) {
                userId = cookie.value;
                [cookieJar deleteCookie:cookie];
            }
        }
    }

@thedarkcder
Copy link

Can you tell me how to use the accesstoken? I am still unauthorised when i tried to make a secure call with this in the header.

@benmarten
Copy link

Do you set the access token then to your LBRESTAdapter?
[_adapter setAccessToken:existingAccessToken];

@thedarkcder
Copy link

I figured this out. The token is signed so I had to get the unsigned value to make the secure call.

res.cookie('access-token', req.signedCookies['access_token']);
res.cookie('userId', req.signedCookies['userId']);

@Zeralith
Copy link

Thanks to everyone for their information and for making this example project.

I believe that loopback-component-passport needs to add support for passport-facebook-token (https://github.com/drudge/passport-facebook-token) so that we can just send POSTs from the iOS and Android Facebook SDKs, to login with Facebook at least in the correct manner, to then start interacting with the API via mobile. It'd be great if this were to happen and for this example project to be updated when it does.

@paomosca
Copy link

1+ @Zeralith

2 similar comments
@YsnKsy
Copy link

YsnKsy commented Jul 1, 2015

1+ @Zeralith

@NelsonBrandao
Copy link

1+ @Zeralith

@bachirelkhoury
Copy link

+1 @Zeralith has there been any progress on this or need any help?

@swapnilg
Copy link

1+ @Zeralith any update ?

@superkhau
Copy link
Contributor

@raymondfeng ^

@philipheinser
Copy link

1+ @Zeralith @raymondfeng @superkhau

@superkhau superkhau added the major label Nov 8, 2015
@artmunro
Copy link

artmunro commented Jan 7, 2016

Can anyone give update if this is now supported? I see the passport-facebook module being used.

@NelsonBrandao
Copy link

@artmunro Its not.

But you can add passport-facebook-token to your package.json and update the module on providers.json to

"module": "passport-facebook-token"

Finally fork loopback-component-passport and do something like this wearescytale/loopback-component-passport@1d2571d#diff-0d9ea68c1756ce2fc5c960b5796850aaR516

@RichardLindhout
Copy link

+1

@always-akshat
Copy link

@NelsonBrandao, I added passport-facebook-token to my package.json and changed facebook-login.provider to passport-facebook-token in providers.json. I also made the changes to passport-configurator.js as suggested. I am getting the following error when I start my server.

  if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requires a authorizationURL option'); }
                                   ^

TypeError: OAuth2Strategy requires a authorizationURL option
    at new OAuth2Strategy (/Users/Akshat/Projects/loopback-social-example/loopback-example-passport/node_modules/passport-oauth2/lib/strategy.js:82:42)
    at PassportConfigurator.configureProvider (/Users/Akshat/Projects/loopback-social-example/loopback-example-passport/node_modules/loopback-component-passport/lib/passport-configurator.js:396:26)
    at Object.<anonymous> (/Users/Akshat/Projects/loopback-social-example/loopback-example-passport/server/server.js:78:24)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)
    at node.js:966:3


Do you have any Idea about the error ?

@mplaza
Copy link

mplaza commented Apr 29, 2016

@always-akshat the "TypeError: OAuth2Strategy requires a authorizationURL option" is because of drudge/passport-facebook-token#36

from PassportConfigurator.prototype.configureProvider:

var AuthStrategy = require(options.module)[options.strategy || 'Strategy'];

  if (!AuthStrategy) {
    AuthStrategy = require(options.module);
  }

require('passport-facebook-token').Strategy throws the error

adding a "strategy" option to the providers.json for the passport-facebook-token module that causes !AuthStrategy to be true worked for me for now

@Code-Crash
Copy link

+1

@TrevorPage
Copy link

I am not sure if this helps to answer the original issue raised, but I am personally successfully using loopback-passport so that my Android application can use Google OAuth to log into my Loopback backend. I had to spend quite a lot of time on this to get it to work, particularly concerning how to handle the various tokens.

I can do a more detailed write-up about this if anyone would like me to. However, briefly off the top of my head, it was something like this:

  • I used the Android SignIn library in my application. This allows the application to fire up an Activity for the user to confirm they want to allow sign in using Google. Then the library gets the token from Google.

  • I then call the Loopback passport endpoint with that token. I can't remember what it is from memory (something like /google/oauth/callback/)). If Loopback/Passport then successfully redeems this token with Google, the response to this endpoint then contains a set-cookie: header.

  • I have to parse/unsign the set-cookie header value to recover the Loopback authentication token. From that point I have a Loopback authentication token that I would use exactly the same as if I'd logged in using conventional username/password.

The only problem I have still to solve is dealing with the auth token TTL. Obviously because it's obtained using OAuth, my app can't store a conventional username/password to get a new one if it needs to. One solution might be to implement a rolling TTL, which I think is what I'm going to do.

@dreamdevil00
Copy link

+1 . I think it will be better if this module supports SPA.

@jackrvaughan
Copy link

+1

Trying to figure out how to use loopback-component-passport for third-party authentication with my SPA and can't seem to find any good examples.

@dosstx
Copy link

dosstx commented May 4, 2018

Will LB4 support SPA?

@jackrvaughan
Copy link

@dosstx LB3 supports SPAs - can't image LB4 wouldn't

@dosstx
Copy link

dosstx commented May 9, 2018

@jackrvaughan Sorry for the confusion. Is it that this module doesn't support SPA? For my SPA (VueJS) with enterprise security service (no social networks), I need to use implicit grant type, hence no client secret needed. Will that be OK for this module?

Trying to understand before I spend time working with it for my SPA. Thanks.

@haresh333
Copy link

I am not sure if this helps to answer the original issue raised, but I am personally successfully using loopback-passport so that my Android application can use Google OAuth to log into my Loopback backend. I had to spend quite a lot of time on this to get it to work, particularly concerning how to handle the various tokens.

I can do a more detailed write-up about this if anyone would like me to. However, briefly off the top of my head, it was something like this:

  • I used the Android SignIn library in my application. This allows the application to fire up an Activity for the user to confirm they want to allow sign in using Google. Then the library gets the token from Google.
  • I then call the Loopback passport endpoint with that token. I can't remember what it is from memory (something like /google/oauth/callback/)). If Loopback/Passport then successfully redeems this token with Google, the response to this endpoint then contains a set-cookie: header.
  • I have to parse/unsign the set-cookie header value to recover the Loopback authentication token. From that point I have a Loopback authentication token that I would use exactly the same as if I'd logged in using conventional username/password.

The only problem I have still to solve is dealing with the auth token TTL. Obviously because it's obtained using OAuth, my app can't store a conventional username/password to get a new one if it needs to. One solution might be to implement a rolling TTL, which I think is what I'm going to do.

Hi
I am interested and want to implement in my mobile app. can you provide writeup or more details

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests