Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,41 @@ export class SigninComponent implements OnInit {

}
```
In `the profile component,the page After login you give your user the access profile.component.ts`,
```javascript
public unlinkaccount(socialPlatform : string) {
let socialPlatformProvider;
if(socialPlatform === "facebook"){
socialPlatformProvider = FacebookLoginProvider.PROVIDER_ID;
socialPlatformProvider = GoogleLoginProvider.PROVIDER_ID;
this.socialAuthService.revokeAccess(this.userid).then(
(revokeres) => {
console.log(revokeres);
//the url to redirect after revocation
this.router.navigate(['/login',{unlinkmessage:'You have successfully unlinked your account'}]);
}
);
}else if(socialPlatform === "google"){
socialPlatformProvider = GoogleLoginProvider.PROVIDER_ID;
this.socialAuthService.revokeAccess(this.userid).then(
(revokeres) => {
console.log(revokeres);
//the url to redirect after revocation
this.router.navigate(['/login',{unlinkmessage:revokeres}]);
}
);
}
}
```
In `profile.component.html`
```html
<h1>
Unlink {{provider}} Account
</h1>



<button (click)="unlinkaccount(provider)" *ngIf="provider" color="warn">Unlink {{provider}} account</button>

```
In `signin.component.html`,

```html
Expand Down
20 changes: 19 additions & 1 deletion src/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,23 @@ export class AuthService {
}
});
}

revokeAccess(userid:string): Promise<any> {
var _this = this;
return new Promise(function (resolve, reject) {
if (_this._user && _this._user.provider) {
let /** @type {?} */ providerId = _this._user.provider;
let /** @type {?} */ providerObject = _this.providers.get(providerId);
providerObject.revokeAccess(userid).then(function (revokeres) {
_this._user = null;
_this._authState.next(null);
resolve(revokeres);
}).catch(function (err) {
_this._authState.next(null);
});
}
else {
reject(AuthService.LOGIN_PROVIDER_NOT_FOUND);
}
});
}
}
2 changes: 1 addition & 1 deletion src/entities/base-login-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export abstract class BaseLoginProvider implements LoginProvider {
abstract initialize(): Promise<SocialUser>;
abstract signIn(): Promise<SocialUser>;
abstract signOut(): Promise<any>;

abstract revokeAccess(userid:string):Promise<any>;
loadScript(obj: LoginProviderClass, onload: any): void {
if (document.getElementById(obj.name)) { return; }
let signInJS = document.createElement('script');
Expand Down
1 change: 1 addition & 0 deletions src/entities/login-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export interface LoginProvider {
initialize(): Promise<SocialUser>;
signIn(): Promise<SocialUser>;
signOut(): Promise<any>;
revokeAccess(userid:string):Promise<any>;
}

8 changes: 7 additions & 1 deletion src/providers/facebook-login-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ export class FacebookLoginProvider extends BaseLoginProvider {
});
});
}

revokeAccess(userid:string): Promise<any>{
return new Promise(function (resolve, reject) {
FB.api(`/${userid}/permissions`,'DELETE',{},function (response) {
resolve('Account Unlink success');
});
});
}
}
13 changes: 13 additions & 0 deletions src/providers/google-login-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,18 @@ export class GoogleLoginProvider extends BaseLoginProvider {
});
});
}
revokeAccess(userid:string): Promise<any>{
var _this = this;
return new Promise(function (resolve, reject) {
_this.auth2.disconnect().then(function (err) {
if (err) {
reject(err);
}
else {
resolve('Google account Unlink success');
}
});
});
}

}