Giter Site home page Giter Site logo

abacritt / angularx-social-login Goto Github PK

View Code? Open in Web Editor NEW
619.0 24.0 390.0 6.13 MB

Social login and authentication module for Angular 17

TypeScript 88.32% JavaScript 4.83% CSS 0.44% HTML 6.33% Shell 0.09%
social-login facebook-login google-login facebook-authentication google-authentication angular

angularx-social-login's Introduction

Angular Social Login

Use Discussions for questions.

Social login and authentication module for Angular 16. Supports authentication with Google, Facebook, Amazon, Microsoft, and VK out of the box. Can be extended to other providers also.

Check out the demo.

Compatibility Matrix

Library Version Angular Version
@abacritt/angularx-social-login:2.1.X 16, 17
@abacritt/angularx-social-login:2.0.X 15, 16
@abacritt/angularx-social-login:1 13, 14, 15
angularx-social-login:4 12, 13
angularx-social-login:3 9, 10, 11
angularx-social-login:2 5, 6, 7, 8

Getting started

Install via npm

npm i @abacritt/angularx-social-login

Import the module

In your AppModule, import the SocialLoginModule

import { SocialLoginModule, SocialAuthServiceConfig } from '@abacritt/angularx-social-login';
import {
  GoogleLoginProvider,
  FacebookLoginProvider
} from '@abacritt/angularx-social-login';

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    SocialLoginModule
  ],
  providers: [
    {
      provide: 'SocialAuthServiceConfig',
      useValue: {
        autoLogin: false,
        lang: 'en',
        providers: [
          {
            id: GoogleLoginProvider.PROVIDER_ID,
            provider: new GoogleLoginProvider(
              'clientId'
            )
          },
          {
            id: FacebookLoginProvider.PROVIDER_ID,
            provider: new FacebookLoginProvider('clientId')
          }
        ],
        onError: (err) => {
          console.error(err);
        }
      } as SocialAuthServiceConfig,
    }
  ],
  bootstrap: [...]
})
export class AppModule { }

Sign in and out users

import { SocialAuthService } from "@abacritt/angularx-social-login";
import { FacebookLoginProvider } from "@abacritt/angularx-social-login";

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent {

  constructor(private authService: SocialAuthService) { }

  signInWithFB(): void {
    this.authService.signIn(FacebookLoginProvider.PROVIDER_ID);
  }

  signOut(): void {
    this.authService.signOut();
  }

}

Sign in with google

GoogleLoginProvider has no signIn() method as other providers, the login flow is triggered by a button that the gis client is generating. Calling SocialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID) will have no effect.

Instead make sure you subscribed to the authentication state and add the following GoogleSigninButtonDirective (exported from the GoogleSigninButtonModule) to your component template to wrap the 'Sign In With Google' button:

ALSO

Check out the Google button generator. Link to Button attributes

<asl-google-signin-button type='icon' size='medium'></asl-google-signin-button>

Options:

Name Type Value Default
type string 'icon' or 'standard' 'icon'
size string 'small', 'medium' or 'large' 'medium'
shape string 'square','circle','pill' or 'rectangular' 'rectangular'
text string 'signin_with','signup_with'or 'continue_with' 'signin_with'
width string '200 - 400 '
theme string 'outline','filled_blue' or 'filled_black' 'outline'
logo_alignment string 'left' or 'center' 'left'

This will only work if the GoogleLoginProvider is registered in SocialAuthServiceConfig.

Refresh google Auth Token

Once a user is logged in manual refresh token method can be triggered

import { SocialAuthService } from "@abacritt/angularx-social-login";
import { GoogleLoginProvider } from "@abacritt/angularx-social-login";

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent implements OnInit {

  constructor(private authService: SocialAuthService) { }

  refreshToken(): void {
    this.authService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID);
  }

}

Request google Access Token

Once a user is logged in an access token can be requested for the scopes we specified in GoogleInitOptions.scopes, you can then reuse this access token to make calls to google apis

import { HttpClient } from '@angular/common/http';
import { SocialAuthService } from "@abacritt/angularx-social-login";
import { GoogleLoginProvider } from "@abacritt/angularx-social-login";

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent implements OnInit {

  private accessToken = '';

  constructor(private authService: SocialAuthService, private httpClient: HttpClient) { }

  getAccessToken(): void {
    this.authService.getAccessToken(GoogleLoginProvider.PROVIDER_ID).then(accessToken => this.accessToken = accessToken);
  }

  getGoogleCalendarData(): void {
    if (!this.accessToken) return;

    this.httpClient
      .get('https://www.googleapis.com/calendar/v3/calendars/primary/events', {
        headers: { Authorization: `Bearer ${this.accessToken}` },
      })
      .subscribe((events) => {
        alert('Look at your console');
        console.log('events', events);
      });
  }
}

Refresh google Access Token

Once a user is logged in and an access token was obtained, the access token can be refreshed (revoked)

import { SocialAuthService } from "@abacritt/angularx-social-login";
import { GoogleLoginProvider } from "@abacritt/angularx-social-login";

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent implements OnInit {

  constructor(private authService: SocialAuthService) { }

  refreshToken(): void {
    this.authService.refreshAccessToken(GoogleLoginProvider.PROVIDER_ID);
  }

}

Subscribe to the authentication state

You are notified when user logs in or logs out. You receive a SocialUser object when the user logs in and a null when the user logs out. SocialUser object contains basic user information such as name, email, photo URL, etc. along with the auth_token. You can communicate the auth_token to your server to authenticate the user in server and make API calls from server.

import { SocialAuthService } from "@abacritt/angularx-social-login";
import { SocialUser } from "@abacritt/angularx-social-login";

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent implements OnInit {

  user: SocialUser;
  loggedIn: boolean;

  constructor(private authService: SocialAuthService) { }

  ngOnInit() {
    this.authService.authState.subscribe((user) => {
      this.user = user;
      this.loggedIn = (user != null);
    });
  }

}

Display the user information

<img src="{{ user.photoUrl }}" referrerpolicy="no-referrer">
<div>
  <h4>{{ user.name }}</h4>
  <p>{{ user.email }}</p>
</div>

Custom Provider

We can use a custom provider, implementing our own logic and needs like the following example:

@Injectable({ providedIn: 'root' })
export class MyCustomLoginProvider extends BaseLoginProvider {
  public static readonly PROVIDER_ID = 'CUSTOM' as const;

  constructor(/* infinite list of dependencies*/) {}
}
@NgModule({
  declarations: [AppComponent, NavbarComponent, DemoComponent],
  imports: [BrowserModule, FormsModule, SocialLoginModule],
  providers: [
    {
      provide: 'SocialAuthServiceConfig',
      useValue: {
        autoLogin: true,
        lang: 'en',
        providers: [
          {
            id: MyCustomLoginProvider.PROVIDER_ID,
            provider: MyCustomLoginProvider,
          },
        ],
      } as SocialAuthServiceConfig,
    },
  ],

Specifying custom scopes, fields etc. on initialization

const fbLoginOptions = {
  scope: 'pages_messaging,pages_messaging_subscriptions,email,pages_show_list,manage_pages',
  return_scopes: true,
  enable_profile_selector: true
}; // https://developers.facebook.com/docs/reference/javascript/FB.login/v2.11

const googleLoginOptions: GoogleInitOptions = {
  oneTapEnabled: false, // default is true
  scopes: 'https://www.googleapis.com/auth/calendar.readonly'
}; // https://developers.google.com/identity/oauth2/web/guides/use-token-model#initialize_a_token_client

const vkLoginOptions = {
  fields: 'photo_max,contacts', // Profile fields to return, see: https://vk.com/dev/objects/user
  version: '5.124', // https://vk.com/dev/versions
}; // https://vk.com/dev/users.get

let config = [
  {
    id: GoogleLoginProvider.PROVIDER_ID,
    provider: new GoogleLoginProvider("Google-OAuth-Client-Id", googleLoginOptions)
  },
  {
    id: FacebookLoginProvider.PROVIDER_ID,
    provider: new FacebookLoginProvider("Facebook-App-Id", fbLoginOptions)
  },
  {
    id: VKLoginProvider.PROVIDER_ID,
    provider: new VKLoginProvider("VK-App-Id", vkLoginOptions)
  },
];

Specifying custom scopes, fields etc. on login

const fbLoginOptions = {
  scope: 'pages_messaging,pages_messaging_subscriptions,email,pages_show_list,manage_pages'
}; // https://developers.facebook.com/docs/reference/javascript/FB.login/v2.11

this.authService.signIn(FacebookLoginProvider.PROVIDER_ID, fbLoginOptions);

Providers

Provider Documentation
MicrosoftLoginProvider Link

Running the demo app

ng build lib
ng serve

angularx-social-login's People

Contributors

acanewby avatar bleuscyther avatar bodinaren avatar bovandersteene avatar carbon-wpa avatar dependabot[bot] avatar evgenii-petukhov avatar filosssof avatar github-actions[bot] avatar gnurub avatar halynsky avatar heatmanofurioso avatar jaibatrik avatar jin-k avatar jonstelly avatar kangw3n avatar kattoshi avatar kristianekman avatar lianyi avatar markarik avatar maryum375 avatar mokipedia avatar nicolasroehm avatar philipp-stsm avatar phuchieuct93abc avatar ranma42 avatar renan-alves avatar rubentrf avatar somcoder avatar spaeda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angularx-social-login's Issues

complie error

ERROR in Error encountered resolving symbol values statically. Calling function 'SocialLoginModule', function calls are not supported. Consider replacing the function or lambda with a
reference to an exported function, resolving symbol AppModule in D:/GitHub/hairbook/src/app/app.module.ts, resolving symbol AppModule in D:/GitHub/hairbook/src/app/app.module.ts

how to fix it.....

AoT compilation not working

There are compilation errors when we execute ng build. SocialLoginModule is not resolved in app.module.ts files.

Sent from my Motorola XT1572 using FastHub

Error when trying to launch Google Login at component init

Hi, i'm trying to launch the authentification on application startup but i get the following console error:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'signIn' of undefined TypeError: Cannot read property 'signIn' of undefined at eval (angularx-social-login.es5.js:26667) at new ZoneAwarePromise (zone.js:875) at GoogleLoginProvider.signIn (angularx-social-login.es5.js:26666) at eval (angularx-social-login.es5.js:22584) at new ZoneAwarePromise (zone.js:875) at AuthService.signIn (angularx-social-login.es5.js:22581) at SigninService.signInWithGoogle (signin.service.ts:50) at SigninService.socialSignIn (signin.service.ts:54) at SigninComponent.connectToGoogle (signin.component.ts:19) at SafeSubscriber.eval [as _error] (signin.component.ts:29) at eval (angularx-social-login.es5.js:26667) at new ZoneAwarePromise (zone.js:875) at GoogleLoginProvider.signIn (angularx-social-login.es5.js:26666) at eval (angularx-social-login.es5.js:22584) at new ZoneAwarePromise (zone.js:875) at AuthService.signIn (angularx-social-login.es5.js:22581) at SigninService.signInWithGoogle (signin.service.ts:50) at SigninService.socialSignIn (signin.service.ts:54) at SigninComponent.connectToGoogle (signin.component.ts:19) at SafeSubscriber.eval [as _error] (signin.component.ts:29) at resolvePromise (zone.js:809) at resolvePromise (zone.js:775) at eval (zone.js:858) at ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:4724) at ZoneDelegate.invokeTask (zone.js:420) at Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595) at ZoneTask.invokeTask [as invoke] (zone.js:500) at invokeTask (zone.js:1517)

angular-cli (angular4) SocialLoginModule is not an NgModule

Hi Guys,

Trying to follow the documentation after installing the social plugin. Under app.module.ts import of the following (below) are not being recognized. Any ideas?

import { SocialLoginModule, AuthServiceConfig } from "angular4-social-login";
import { GoogleLoginProvider, FacebookLoginProvider } from "angular4-social-login"

Also, after cloning the repo and running "demo" i get the following errors:

Rodrigo:demo$ ng serve
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
Hash: 97f2a0064514b882f1ea
Time: 13682ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.js.map (main) 10.6 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 3.27 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

ERROR in SocialLoginModule is not an NgModule
webpack: Failed to compile.

Cheers

Cannot find name 'SocialUser'

Cannot find name 'SocialUser'. How to fix?

ERROR in src/app/app.component.ts(12,17): error TS2304: Cannot find name 'SocialUser'.

webpack: Compiling...
Date: 2017-11-03T16:07:37.658Z
Hash: 71d981ca744881c80e1e
Time: 301ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry]
chunk {main} main.bundle.js (main) 25.6 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 598 kB [initial]
chunk {styles} styles.bundle.js (styles) 33.4 kB [initial]
chunk {vendor} vendor.bundle.js (vendor) 9.81 MB [initial]

Cannot call AuthServiceConfig constructor in AppModule

We are building an Angular 4 project and needed social login.
We followed the README instructions and declare a new AuthServiceConfig as follows:

let config = new AuthServiceConfig([
  {
    id: GoogleLoginProvider.PROVIDER_ID,
    provider: new GoogleLoginProvider("Google-OAuth-Client-Id")
  },
  {
    id: FacebookLoginProvider.PROVIDER_ID,
    provider: new FacebookLoginProvider("Facebook-App-Id")
  }
])

When serving the app through angular cli (via ng serve) we get the following error:

ERROR in Error: Error encountered resolving symbol values statically. Calling function 'AuthServiceConfig', fun
ction calls are not supported. Consider replacing the function or lambda with a reference to an exported functi
on, resolving symbol config in C:/Users/USER/Desktop/PROJECT/src/app/app.module.ts,
resolving symbol AppModule in 
    at Error (native)
    at syntaxError 
[... OMITTED...]

AoT not working again

Well, I am using this plugin (awesome btw!), but I can't do a AoT build because of it.
This is my app.module.ts and my ng build --prod stacktrace

import { NgModule } from '@angular/core';
(...)

const config = new AuthServiceConfig([
  {
    id: GoogleLoginProvider.PROVIDER_ID,
    provider: new GoogleLoginProvider('583729964953-colv9g62m813om4s1p5thtlqdv9ig46c.apps.googleusercontent.com')
  },
  {
    id: FacebookLoginProvider.PROVIDER_ID,
    provider: new FacebookLoginProvider('347701065702510')
  }
]);

export function provideConfig() {
  return config;
}

@NgModule({
      imports: [
          (...)
          SocialLoginModule
      ],
      declarations: [
          AppComponent,
          LoginComponent,
          HomeComponent,
          FestivalsComponent
      ],
      providers: [
          (...),
          {
            provide: AuthServiceConfig,
            useFactory: provideConfig
          }
      ],
      bootstrap: [AppComponent]
  })

  export class AppModule { }
filipemendes@MacBook-Pro-de-Filipe:~/dev/mistaker-maker/web-app$ ng build --prod
Date: 2017-11-18T23:27:07.414Z                                                          
Hash: b7566c89f11e42ae3006
Time: 37673ms
chunk {0} main.d383bc3ff89eb6533d48.bundle.js (main) 659 kB [initial] [rendered]
chunk {1} polyfills.e6475d2787bb3154d59c.bundle.js (polyfills) 60.9 kB [initial] [rendered]
chunk {2} styles.532043307593380cd798.bundle.css (styles) 234 bytes [initial] [rendered]
chunk {3} inline.e5a722ba293bced87b37.bundle.js (inline) 1.45 kB [entry] [rendered]

ERROR in ./node_modules/rxjs/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:9341:17)
    at assignContextualParameterTypes (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41948:29)
    at checkExpressionWorker (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42959:28)
    at checkExpression (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42898:42)
    at checkExpressionCached (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42779:38)
    at checkReturnStatement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:45418:54)
    at checkSourceElement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46763:28)
    at Object.forEach (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:1506:30)
    at checkBlock (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:44563:16)
    at checkSourceElement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46742:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41990:21)
    at checkDeferredNodes (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46828:25)
    at checkSourceFileWorker (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46863:17)
    at checkSourceFile (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46842:13)
    at Object.forEach (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:1506:30)
 @ ./node_modules/rxjs/observable/bindCallback.js 2:32-68
 @ ./node_modules/rxjs/add/observable/bindCallback.js
 @ ./node_modules/rxjs/Rx.js
 @ ./node_modules/angular4-social-login/angular4-social-login.umd.js
 @ ./src/app/app.module.ngfactory.js
 @ ./src/main.ts
 @ multi ./src/main.ts
ERROR in ./node_modules/rxjs/observable/BoundNodeCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:9341:17)
    at assignContextualParameterTypes (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41948:29)
    at checkExpressionWorker (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42959:28)
    at checkExpression (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42898:42)
    at checkExpressionCached (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:42779:38)
    at checkReturnStatement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:45418:54)
    at checkSourceElement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46763:28)
    at Object.forEach (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:1506:30)
    at checkBlock (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:44563:16)
    at checkSourceElement (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46742:28)
    at checkFunctionExpressionOrObjectLiteralMethodDeferred (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:41990:21)
    at checkDeferredNodes (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46828:25)
    at checkSourceFileWorker (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46863:17)
    at checkSourceFile (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:46842:13)
    at Object.forEach (/Users/filipemendes/dev/mistaker-maker/web-app/node_modules/typescript/lib/typescript.js:1506:30)
 @ ./node_modules/rxjs/observable/bindNodeCallback.js 2:36-76
 @ ./node_modules/rxjs/add/observable/bindNodeCallback.js
 @ ./node_modules/rxjs/Rx.js
 @ ./node_modules/angular4-social-login/angular4-social-login.umd.js
 @ ./src/app/app.module.ngfactory.js
 @ ./src/main.ts
 @ multi ./src/main.ts

I hope someone can help me, please

localdeploy script not found

I'm trying to test some local changes, but your instructions for running a local test of the demo package doesn't seem to work, because the localdeploy script is missing.

Command tried:
npm run localdeploy

Error returned:
npm ERR! missing script: localdeploy

How to pass Client id dynamic.

Hi, I am getting google client id my custom api. So please tell me how to pass this client id on social auth service. Pass client id on login button click.

On facebook login calls twice to track event fb_page_view

Hello,

We are using angular4-social-login for manage our social logins, and we think we found an issue:
When the buttons are shown, it seems to track twice an event "fb_page_view", as you can see on the next screenshot, from the demo:
image

We debug the library, and we think we found the cause. On the file https://github.com/abacritt/angular4-social-login/blob/master/src/providers/facebook-login-provider.ts, on line 24 it has:
FB.AppEvents.logPageView();
After, it has a FB.getLoginStatus call. We think there are these two calls which do the twice 'fb_page_view' call. We have done some tests, and it seems that if we delete the 24th line, (FB.getLoginStatus), we still can log in with FB account, get the user info, and the track event is not called twice.

If possible, could you, please, tell us if the deletion of the line is ok, and, if you can again, do a change for that?

Regards

Not working on PWA

It is not working only on PWA mode..
It is restarts app after social login.
Is there any solutions ?????

FB Login

fb login returns empty user after login but that of google works fine

Ionic

Hey, the module is working well on a simple browser but in a ionic app (with angular 4) the popup for signing in doesn't pop up.

Bug when build

app.module

...
import { SocialLoginModule, AuthServiceConfig, FacebookLoginProvider } from 'angularx-social-login';

let config = new AuthServiceConfig([
	{
		id: FacebookLoginProvider.PROVIDER_ID,
		provider: new FacebookLoginProvider('416759688716123')
	}
]);

@NgModule({
...
	imports: [
...
		SocialLoginModule.initialize(config),
...
	],
...
})
export class AppModule { }

Error
Error in console

Package version.

Angular: 5.2.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.5
@angular-devkit/build-optimizer: 0.0.41
@angular-devkit/core: 0.0.28
@angular-devkit/schematics: 0.0.51
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.5
@schematics/angular: 0.1.16
typescript: 2.6.2
webpack: 3.10.0

handle error when social popup is closed

I integrated this module and its working fine. But If I choose signin with google or facebook and then decide to close the popup without signing in then error should be handled. But I am not able to handle this event. please help.

Unable to signout

Hi Guys,

I manage to login ok, however, when trying to logout i get the following error:

Using the following to signout:

signOut(): void { this.authService.signOut(); }

core.es5.js:1020 ERROR Error: Uncaught (in promise): Login provider not found at resolvePromise (zone.js:783) at zone.js:709 at ng4-social-login.umd.js:88 at new ZoneAwarePromise (zone.js:847) at AuthService.webpackJsonp.../../../../ng4-social-login/ng4-social-login.umd.js.AuthService.signOut (ng4-social-login.umd.js:75)

Push dist files

Maybe you should push dist files we can find in the package.json like:

  "main": "./bundles/angularx-social-login.umd.js",
  "module": "./angularx-social-login.es5.js",
  "es2015": "./angularx-social-login.js",
  "typings": "./angularx-social-login.d.ts",

It would be possible to refer to a specific commit of your lib in the package.json dependencies

not able to signin with google

hi, On Page load , I am getting this error
uO {message: "gapi.auth2 has been initialized with different opt…2.getAuthInstance() instead of gapi.auth2.init().", stack: "gapi.auth2.ExternallyVisibleError: gapi.auth2 has …5bVcX6l_LBMW9kRaNn7eGxqL7Sg/cb=gapi.loaded_1:1:15"}

And when I try to signin with google, I got this error
TypeError: Cannot read property 'signIn' of undefined
TypeError: Cannot read property 'signIn' of undefined
at angular4-social-login.umd.js:245
at new ZoneAwarePromise (zone.js:890)
at GoogleLoginProvider.webpackJsonp.../../../../angular4-social-login/angular4-social-login.umd.js.GoogleLoginProvider.signIn (angular4-social-login.umd.js:244)
at angular4-social-login.umd.js:58
at new ZoneAwarePromise (zone.js:890)
at AuthService.webpackJsonp.../../../../angular4-social-login/angular4-social-login.umd.js.AuthService.signIn (angular4-social-login.umd.js:55)
at LoginComponent.webpackJsonp.../../../../../src/app/auth/components/login/login.component.ts.LoginComponent.signInWithGoogle (login.component.ts:73)
at Object.eval [as handleEvent] (LoginComponent.html:20)
at handleEvent (core.es5.js:11998)
at callWithDebugContext (core.es5.js:13467)
at angular4-social-login.umd.js:245
at new ZoneAwarePromise (zone.js:890)
at GoogleLoginProvider.webpackJsonp.../../../../angular4-social-login/angular4-social-login.umd.js.GoogleLoginProvider.signIn (angular4-social-login.umd.js:244)
at angular4-social-login.umd.js:58
at new ZoneAwarePromise (zone.js:890)
at AuthService.webpackJsonp.../../../../angular4-social-login/angular4-social-login.umd.js.AuthService.signIn (angular4-social-login.umd.js:55)
at LoginComponent.webpackJsonp.../../../../../src/app/auth/components/login/login.component.ts.LoginComponent.signInWithGoogle (login.component.ts:73)
at Object.eval [as handleEvent] (LoginComponent.html:20)
at handleEvent (core.es5.js:11998)
at callWithDebugContext (core.es5.js:13467)
at resolvePromise (zone.js:824)
at resolvePromise (zone.js:795)
at zone.js:873
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
at Object.onInvokeTask (core.es5.js:3881)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask (zone.js:192)
at drainMicroTaskQueue (zone.js:602)
at ZoneTask.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:503)
at invokeTask (zone.js:1540)
defaultErrorLogger @ core.es5.js:1020
webpackJsonp.../../../core/@angular/core.es5.js.ErrorHandler.handleError @ core.es5.js:1080
next @ core.es5.js:4503
schedulerFn @ core.es5.js:3635
webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:239
webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.SafeSubscriber.next @ Subscriber.js:186
webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber._next @ Subscriber.js:127
webpackJsonp.../../../../rxjs/_esm5/Subscriber.js.Subscriber.next @ Subscriber.js:91
webpackJsonp.../../../../rxjs/_esm5/Subject.js.Subject.next @ Subject.js:56
webpackJsonp.../../../core/@angular/core.es5.js.EventEmitter.emit @ core.es5.js:3621
(anonymous) @ core.es5.js:3912
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:392
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run @ zone.js:142
webpackJsonp.../../../core/@angular/core.es5.js.NgZone.runOutsideAngular @ core.es5.js:3844
onHandleError @ core.es5.js:3912
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:396
webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runGuarded @ zone.js:158
_loop_1 @ zone.js:702
api.microtaskDrainDone @ zone.js:711
drainMicroTaskQueue @ zone.js:610
webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:503
invokeTask @ zone.js:1540
globalZoneAwareCallback @ zone.js:1566
please help

Getting unexpected value 'SocialLoginModule'

Hi,

I used you work around for the AOT compilations.

Im receiving an error when trying to push to production.

remote:        ERROR in Unexpected value 'SocialLoginModule in /tmp/build_3c514eb8278c6a857f76b5d21d5ae9f7/node_modules/angular4-social-login/dist/lib/sociallogin.module.d.ts' imported by the module 'AppModule in /tmp/build_3c514eb8278c6a857f76b5d21d5ae9f7/src/app/app.module.ts'. Please add a @NgModule annotation.
remote:        
remote:        ERROR in ./src/main.ts
remote:        Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/tmp/build_3c514eb8278c6a857f76b5d21d5ae9f7/src'
remote:        @ ./src/main.ts 3:0-74
remote:        @ multi ./src/main.ts

Was wondering what solutions I have?

I dont see any issues as far as the code written. Seems to be pretty straigthforward on your docs.

Here is my service.ts

import { BrowserModule } from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import { FormsModule } from "@angular/forms"
import { AppComponent } from './app.component';
import {AppRoutingModule} from "./app-routing.module";
import {UserService} from "./user/user.service";
import {LandingPageComponent} from "./landing-page/landing-page.component";
import {HttpClientModule} from "@angular/common/http";
import {NavComponent} from "./nav/nav.component";
import {FooterComponent} from "./footer/footer.component";
import {UiService} from "./ui.service";
import {environment} from "../environments/environment";
import {ContactService} from "./contact/contact.service";
import {ContactComponent} from "./contact/contact.component";
import { SocialLoginModule, AuthServiceConfig, GoogleLoginProvider, FacebookLoginProvider } from "angular4-social-login";

let config = new AuthServiceConfig([
  {
    id: GoogleLoginProvider.PROVIDER_ID,
    provider: new GoogleLoginProvider(environment.providers.google.clientId)
  },
  {
    id: FacebookLoginProvider.PROVIDER_ID,
    provider: new FacebookLoginProvider(environment.providers.facebook.clientId)
  }
]);

export function provideConfig() {
  return config;
}

@NgModule({
  declarations: [
    AppComponent,
    LandingPageComponent,
    NavComponent,
    FooterComponent,
    ContactComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
    AppRoutingModule,
    SocialLoginModule

  ],
  providers: [
    UserService,
    UiService,
    ContactService,
    {
      provide: AuthServiceConfig,
      useFactory: provideConfig
    }
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}


Signing API calls?

I've been using Satellizer with AngularJS forever, which took care of all of this, so I'm sorry for the noob question.

Once I'm authenticated with Facebook or Google, how can I pass something to the back end to generate a JWT and validate the Facebook or Google session? I've checked the Local Storage and Session Storage and I don't see anything like a JWT "token." Is there any mechanism to sign an API request and validate it on the back end?

Cannot read property 'provider' of null

If I call this.authService.signOut() when no authentication (session) exists, it throws this error.
Would be nice to just quietly execute with no result if no authentication exists.

Hi I am unable to signout for Google with this code....... Ca n any one give suggestions???

Hi I am unable to signout for Google with this code....... Ca n any one give suggestions???

I implemented as it is in angular4 social login example..................
AuthService.prototype.signOut = function () {
var _this = this;
return new Promise(function (resolve, reject) {
//if (providerObject) {
if (_this._user && _this._user.provider) {
var /** @type {?} / providerId = _this._user.provider;
var /* @type {?} */ providerObject = _this.providers.get(providerId);
providerObject.signOut().then(function () {
_this._user = null;
_this._authState.next(null);
resolve();
// });
}).catch((err) => {
this._authState.next(null);
});
}
else {
reject(AuthService.LOGIN_PROVIDER_NOT_FOUND);
}
});
};
return AuthService;

GoogleLoginProvider.prototype.signOut = function () {
var _this = this;
return new Promise(function (resolve, reject) {
_this.auth2.signOut().then(function (response) {
resolve();
//_this.auth2.signIn(false);
});

Login with more scope

Hi,

I want to publish post message to my wall
Because I'm already connected, I want to do FB.api('me/feed' ...)

But in the module, you're sign in with { scope: 'email,public_profile' }

It would be better if we can choose scope.

can access the user details returned after login

please acessing user object of type SocialUser to get a user authToken or get individual properties seems to break the app why? it useless getting a users login details without been able to use it, please look into ur package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.