MsIdTokenValidator
This library is provided to validate id token from Microsoft Oauth2.
Inspired from the Google ID Token
Disclaimer
I am entirely not affiliated with Microsoft, the code is provided as-is and no warranty.
Installation
Add this line to your application's Gemfile:
gem 'ms-id-token-validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ms-id-token-validator
Usage
validator = MsIdToken::Validator.new
begin
# audience is possibly the Application Client ID
payload = validator.check(id_token, audience)
rescue MsIdToken::IdTokenExpired => ex
puts 'Id token is expired'
end
By default, the public keys fetched from Microsoft are cached in one hour. Microsoft state that their public key should be updated within 24 hours, so our default value is more than enough.
To change the cached expiry, for example, 6 hours, we can pass the value at the time creating the validator.
validator = MsIdToken::Validator.new({expiry: 6 * 3600})
References
Certificate credentials for application authentication
Validate an Exchange identity token
Azure Active Directory v2.0 tokens reference
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/QQism/ms-id-token-validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.