GithubHelp home page GithubHelp logo

batista / vue-slack-oauth2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from guruahn/vue-google-oauth2

0.0 1.0 1.0 101 KB

๐Ÿ”Œ Handling Google sign-in and sign-out for Vue.js applications

License: MIT License

JavaScript 58.94% HTML 23.15% Go 9.08% Python 8.83%

vue-slack-oauth2's Introduction

vue-slack-oauth2

Handling Slack sign-in and sign-out for Vue.js applications. Very much inspired by vue-google-oauth2

npm bundle size GitHub vue-slack-oauth2

Installation

Installation with npm

npm install @batista/vue-slack-oauth2

Installation with yarn

yarn add @batista/vue-slack-oauth2

Initialization

//src/main.js
import SlackAuth from 'vue-slack-oauth2'
const slackAuthOption = {
  clientId: 'CLIENT_ID',
  scope: 'profile email',
  prompt: 'select_account'
}
Vue.use(SlackAuth, slackAuthOption)

Options

Property Type Required Description
clientId String Required. The app's client ID, found and created in the Slack API.
scope String Optional. Default value is profile email.

Methods

Property Description Type
SlackAuth return of Object
isAuthorized Whether or not you have auth Boolean
isInit Whether or not api init Boolean
isLoaded Whether or not api init. will be deprecated. Function
signIn function for sign-in Function
getAuthCode function for getting authCode Function
signOut function for sign-out Function

Usages

Getting authorization code

The authCode that is being returned is the one-time code that you can send to your backend server, so that the server can exchange for its own access_token and refresh_token.

The access_token and refresh_token can be saved in backend storage for reuse and refresh. In this way, you can avoid exposing your api key or secret key whenever you need to use various APIs.

const authCode = await this.$slackAuth.getAuthCode()
const response = await this.$http.post('http://your-backend-server-api-to-use-authcode', { code: authCode, redirect_uri: 'postmessage' })

Sign-in: Directly get back the access_token and id_token

const slackUser = await this.$slackAuth.signIn()
// slackUser.getId() : Get the user's unique ID string.
// slackUser.getBasicProfile() : Get the user's basic profile information.
// slackUser.getAuthResponse() : Get the response object from the user's auth session. access_token and so on
this.isSignIn = this.$slackAuth.isAuthorized

refer to slack signIn reference

Sign-out

Handling Slack sign-out

const response = await this.$slackAuth.signOut()

Extra - Directly get access_token and refresh_token on Server-side

To get access_token and refresh_token in server side, the data for redirect_uri should be postmessage. postmessage is magic value for redirect_uri to get credentials without actual redirect uri.

Curl

curl -d "client_id=YOUR_CLIENT_ID&\
  client_secret=YOUR_CLIENT_SECRET&\
  redirect_uri=postmessage&\
  grant_type=authorization_code&\
  code=YOUR_AUTH_CODE" https://slack.com/api/openid.connect.token

Sample Code

Additional Help

FAQ

The failure of initialization happens

You can check the brower console to check errors which occur during initialization. The most of errors are from inproper setting of slack oauth2 credentials setting in your Slack App configurations. After changing the settings, you have to do hard refresh to clear your caches.

Type Errors

Follow the documentation provided here to add $slackAuth as a property for preventing lint errors.

Acknowledgements

This Package was greatly inspired by @guruahn work on his vue-google-oauth2 package, many thanks for his work. ๐Ÿ™

vue-slack-oauth2's People

Contributors

batista avatar byeongukchoi avatar dzakki avatar fidemin avatar fpierre avatar guruahn avatar h-matsuo avatar jtandiyo avatar katiedotson avatar printscreen avatar romainr avatar supenguin avatar thomasleveil avatar yokoel avatar

Watchers

 avatar

Forkers

simonreeves

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.