Skip to content

espen/omniauth-visma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OmniAuth Visma

This gem contains the unofficial Visma eAccounting strategy for OmniAuth.

See the authorization documentation for Visma eAccounting.

For more information about the API see https://developer.vismaonline.com/.

To easily use the API from Ruby see VismaEaccounting.

Basic Usage

use OmniAuth::Builder do
  provider "visma", ENV['VISMA_CLIENT_ID'], ENV['VISMA_CLIENT_SECRET'], scope: 'offline_access ea:api'
end

Refreshing the access token

The retrieved access_token expires in one hour. So you need to retrieve a new token when it expires. You can do so using the refresh! method in OmniAuth. You will retrieve all new tokens so make sure you save both the access_token and refresh_token.

Example:

if Time.at( visma_access_token_expires_at ).past?
  oauth = OmniAuth::Strategies::Visma.new(nil, {
    client_id: ENV['VISMA_CLIENT_ID'],
    client_secret: ENV['VISMA_CLIENT_SECRET']
  }
  token = OAuth2::AccessToken.new(
    oauth.client,
    visma_access_token,
    { refresh_token: visma_refresh_token }
  )
  new_tokens = token.refresh!
end

You can then use the new access_token and when it expires you can use the new refresh_token to gain a new one.

Credits

Based on omniauth-37signals by Will Barrett.

License

Copyright (c) 2017 by Espen Antonsen. MIT License

About

Omniauth strategy for Visma eAccounting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages