•  


functions-samples/instagram-auth at master · ulukaya/functions-samples · GitHub
Skip to content

Latest commit

 

History

History
 
 

instagram-auth

Folders and files

Name Name
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Use Instagram Sign In with Firebase

This sample shows how to authenticate using Instagram Sign-In on Firebase. In this sample we use OAuth 2.0 based authentication to get Instagram user information then create a Firebase Custom Token (using the Instagram user ID).

Setup the sample

Create and setup the Firebase project:

  1. Create a Firebase project using the Firebase Developer Console .
  2. Enable Billing on your Firebase the project by switching to the Blaze plan, this is currently needed to be able to perform HTTP requests to external services from a Cloud Function.

Create and provide a Service Account's credentials:

  1. Create a Service Accounts file as described in the Server SDK setup instructions .
  2. Save the Service Account credential file as ./functions/service-account.json

Create and setup your Instagram app:

  1. Register an Instagram app on Instagram for Developers . You'll need to Register a New Client .

  2. Once Your app is created make sure you specify your app's callback URL in the list of Valid redirect URIs of your Instagram app. You should whitelist https://localhost:5000/popup.html for local development and if you deploy on App Engine (See Deploy section below) you should whitelist the URL https://<application-id>.firebaseapp.com/popup.html .

  3. Copy the Client ID and Client Secret of your Instagram app and use them to set the instagram.client_id and instagram.client_secret Google Cloud environment variables. For this use:

    firebase functions:config:set instagram.client_id=
    "
    yourClientID
    "
     instagram.client_secret=
    "
    yourClientSecret
    "
    

Make sure the Instagram Client Secret is always kept secret. For instance do not save it in your version control system.

Deploy your project:

  1. Run firebase use --add and choose your Firebase project. This will configure the Firebase CLI to use the correct project locally.
  2. Run firebase deploy to effectively deploy the sample. The first time the Functions are deployed the process can take several minutes.

Run the sample

Open the sample's website by using firebase open hosting:site or directly accessing https://<project-id>.firebaseapp.com/ .

Click on the Sign in with Instagram button and a popup window will appear that will show the Instagram In authentication consent screen. Sign In and/or authorize the authentication request.

The website should display your name and profile pic from Instagram. At this point you are authenticated in Firebase and can use the database/hosting etc...

Workflow and design

When clicking the Sign in with Instagram button a popup is shown which redirects users to the redirect Function URL.

The redirect Function then redirects the user to the Instagram OAuth 2.0 consent screen where (the first time only) the user will have to grant approval. Also the state cookie is set on the client with the value of the state URL query parameter to check against later on.

After the user has granted approval he is redirected back to the ./popup.html page along with an OAuth 2.0 Auth Code as a URL parameter. This Auth code is then sent to the token Function using a JSONP Request. The token function then:

  • Checks that the value of the state URL query parameter is the same as the one in the state cookie.
  • Exchanges the auth code for an access token using the Instagram app credentials and gets the user identity (photoURL and full name).
  • Mints a Custom Auth token (which is why we need Service Accounts Credentials).
  • Returns the Custom Auth Token, photo URL, user display name and Instagram access token to the ./popup.html page.

The ./popup.html receives the Custom Auth Token and other data back from the AJAX request to the token Function and uses it to update the user's profile, saves the access token to the database, authenticate the user in Firebase and then close the popup. At this point the main page will detect the sign-in through the Firebase Auth State observer and display the signed-In user information.

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본