One-12 / Client

0 stars 0 forks source link

Firebase Config #9

Closed arunselvakumar closed 4 years ago

arunselvakumar commented 4 years ago

JWT Token:

"eyJhbGciOiJSUzI1NiIsImtpZCI6ImZjMmM4YmIyNmE3OGM0M2JkODYzNzA1YjNkNzkyMWI0ZTY0MjVkNTQiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiQXJ1biIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS0vQU9oMTRHaDFTQmtrREFHckpnaVFFQW5tUElGU0J5TWptSDRXVUNFR1VVTDZjdyIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9vbmUtMTItZGV2LTE1ODg0MzM3MjEzNTMiLCJhdWQiOiJvbmUtMTItZGV2LTE1ODg0MzM3MjEzNTMiLCJhdXRoX3RpbWUiOjE1ODkwMjkyNDgsInVzZXJfaWQiOiJWNFc4bUdPOHhBTVp0MHhYUldEUGxYdnhIYjYzIiwic3ViIjoiVjRXOG1HTzh4QU1adDB4WFJXRFBsWHZ4SGI2MyIsImlhdCI6MTU4OTAzMjcyMywiZXhwIjoxNTg5MDM2MzIzLCJlbWFpbCI6ImIuYXJ1bnNlbHZha3VtYXJAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZ29vZ2xlLmNvbSI6WyIxMTIyOTYxMjg0OTM3MTY3MDAxMjkiXSwiZW1haWwiOlsiYi5hcnVuc2VsdmFrdW1hckBnbWFpbC5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJnb29nbGUuY29tIn19.gV9QT1vvLM7lSOfqPOQKHgSLy45M7BhtWwLObCWOUB8K4Sq3gA397faKdRcjxU0OHwSsnFSeulE3mrJImQLfLRFmWJGAEuUvG0EJBMeFEoRJ5s3VshMhF5f12kvsTzw-XVmWp7klQM0noMihtewOmtt4_6BtwWLdAlMvnHxs4D6-PE8Ml8dPr4Lws6AxjPIP_zFfBsqB64CgqYxTefSH_jzt2C2z4H8SJ3zal7rp1Bijmq7dmhqEKO54CvK09LIXnWy3RN5eR5ltsncrfCOGYFVLonSrvJZ5hbOwekufdzsbD6267tTYITdk7MZabN2s1qGJY97mfZU7M_CvmGt9Zw"

arunselvakumar commented 4 years ago

const firebaseConfig = { apiKey: 'AIzaSyBj-DGF0P5unpVEAGAi1qFfNF-de3E8a44', authDomain: 'one-12-dev-1588433721353.firebaseapp.com', databaseURL: 'https://one-12-dev-1588433721353.firebaseio.com', projectId: 'one-12-dev-1588433721353', storageBucket: 'one-12-dev-1588433721353.appspot.com', messagingSenderId: '706878206699', appId: '1:706878206699:web:115eb5d5897bf3651dc4ae', measurementId: 'G-LL6K95B1LC', };

arunselvakumar commented 4 years ago

https://dev.to/emeka/securing-your-express-node-js-api-with-firebase-auth-4b5f

arunselvakumar commented 4 years ago

https://itnext.io/how-to-use-firebase-auth-with-a-custom-node-backend-99a106376c8a

arunselvakumar commented 4 years ago

npm i firebase-admin

const serviceAccount = require("config/fbServiceAccountKey.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), databaseURL: "https://fbauthdemo-2a451.firebaseio.com" });

function checkAuth(req, res, next) { if (req.headers.authtoken) { admin.auth().verifyIdToken(req.headers.authtoken) .then(() => { next() }).catch(() => { res.status(403).send('Unauthorized') }); } else { res.status(403).send('Unauthorized') } }

arunselvakumar commented 4 years ago

public getPosts(postRequest: PostRequestModel): Observable { let httpParams = new HttpParams(); httpParams = httpParams.append('page', postRequest.page); httpParams = httpParams.append('offset', String(postRequest.offset)); httpParams = httpParams.append('limit', String(postRequest.limit)); httpParams = httpParams.append('tag', String(postRequest.tag));

const httpHeaders = new HttpHeaders();
httpHeaders.set('Authorization', `Bearer ${this._authService.idToken}`);

const apiUrl = `${this.baseUrl}/api/posts`;
return this._httpClient.get<PostResponseModel>(apiUrl, { params: httpParams });

}

arunselvakumar commented 4 years ago

Closing the issue, since Auth related server changes are merged.