@nodeart/firebase-connector
Advanced tools
Comparing version 2.1.21 to 2.1.22
@@ -28,3 +28,4 @@ { | ||
"zone.js": "0.7.4", | ||
"angularfire2": "2.0.0-beta.7" | ||
"angularfire2": "2.0.0-beta.7", | ||
"firebase": "^3.7.5" | ||
}, | ||
@@ -37,3 +38,3 @@ "devDependencies": { | ||
}, | ||
"version": "2.1.21" | ||
"version": "2.1.22" | ||
} |
@@ -1,1 +0,81 @@ | ||
#Firebase connector | ||
# Firebase connector | ||
**VkAuth** | ||
`vk.com` is not among standard auth providers in firebase, so we provide our own solution for | ||
this. To get acquainted with the flow, please, read [this](https://vk.com/dev/implicit_flow_user) article. | ||
In order to avoid creation of http server, vkAuthService works only with firebase and not with REST API. | ||
So, we strongly recommend to set redirect url to be a current location, thus one can get a token on a client side. | ||
Internal work of a service one can found in [source](./src/authMethods/vk.ts) | ||
**Usage:** | ||
`VkConfigService` declaration | ||
```typescript | ||
//vkAuthConfig.service.ts | ||
import {Injectable} from "@angular.core"; | ||
import {VkAuthConfig, VkConfig, PopupConfig} from "@nodeart/firebase-connector"; | ||
@Injectable() | ||
export class VkConfig implements VkAuthConfig { | ||
public vkConfig : VkConfig = { | ||
client_id: 'app_id', | ||
display: 'popup', | ||
scope: ['friends'], | ||
response_type: 'token', | ||
v: 5.63 | ||
}; | ||
public popupConfig: PopupConfig = { | ||
location: 'no', | ||
height: 600, | ||
width: 600 | ||
}; | ||
public cleanUp: true; | ||
public dbPath: 'vkAuth'; | ||
constructor() { } | ||
} | ||
``` | ||
`VkConfigService` register | ||
```typescript | ||
//someModule.module.ts | ||
import {NgModule} from "@angular/core"; | ||
import {VkConfig} from "./vkAuthConfig.service"; | ||
@NgModule({ | ||
providers: [ | ||
{provide: 'VkAuthConfig', useClass: VkConfig} | ||
] | ||
}) | ||
export class SomeModule { } | ||
``` | ||
Server side or [firebase cloud functions](https://firebase.google.com/docs/functions/) code: | ||
```javascript | ||
'use strict'; | ||
const admin = require('firebase-admin'); | ||
const authWithVk = admin.database().ref('auth/vk'); | ||
const listener = (ref, snapshot) => { | ||
const key = snapshot.key, | ||
val = snapshot.val(); | ||
if (!val.processed) { | ||
admin.auth() | ||
.createCustomToken(val['access_token']) | ||
.then(token => { | ||
const data = Object.assign(val, { | ||
access_token: token, | ||
expires_in: null, | ||
processed: true | ||
}); | ||
ref.child(key).set(data); | ||
return data | ||
}) | ||
.then(data => console.log(`custom token generated = ${JSON.stringify(data)}`)) | ||
} | ||
}; | ||
authWithVk.on('child_added', snapshot => listener(authWithVk, snapshot)); | ||
``` |
@@ -9,6 +9,14 @@ import {NgModule} from "@angular/core"; | ||
import {AnonymouslyAuth} from "./authMethods/anonymously"; | ||
import {VkAuth} from "./authMethods/vk"; | ||
/** | ||
* Firebase connector module | ||
*/ | ||
export { | ||
VkAuthConfig, | ||
PopupConfig, | ||
FbConfig, | ||
VkConfig | ||
} from "./authMethods/vk"; | ||
@NgModule({ | ||
@@ -22,7 +30,8 @@ providers: [ | ||
TwitterAuth, | ||
AnonymouslyAuth | ||
AnonymouslyAuth, | ||
VkAuth | ||
] | ||
}) | ||
export class FirebaseConnectorModule { | ||
} |
39574
22
944
81
12
+ Addedfirebase@^3.7.5