https://github.com/whossname/azure_ad_openid
Azure Active Directory authentication using OpenID
https://github.com/whossname/azure_ad_openid
authentication azure-active-directory azure-ad elixir elixir-lang openid openid-client
Last synced: 6 months ago
JSON representation
Azure Active Directory authentication using OpenID
- Host: GitHub
- URL: https://github.com/whossname/azure_ad_openid
- Owner: whossname
- License: mit
- Created: 2018-11-10T04:20:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-10T22:46:58.000Z (about 1 year ago)
- Last Synced: 2024-11-29T10:14:02.405Z (6 months ago)
- Topics: authentication, azure-active-directory, azure-ad, elixir, elixir-lang, openid, openid-client
- Language: Elixir
- Homepage: https://hexdocs.pm/azure_ad_openid/readme.html
- Size: 65.4 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Azure Active Directory OpenID
[](https://travis-ci.org/whossname/azure_ad_openid)
[](https://hex.pm/packages/azure_ad_openid)
[](http://opensource.org/licenses/MIT)Azure Active Directory authentication using OpenID.
This is a simple and opinionated OpenID authentication library for Azure Active Directory.
The following decisions have been made:- The nonce has a timeout of 15 minutes
- The callback will reject id_tokens with an iat that is more than 6 minutes old## Installation
The package can be installed by adding `azure_ad_openid` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:azure_ad_openid, "~> 0.2"},
]
end
```## Basic Usage
This library can be used with or without the standard Elixir configuration. If you want to
use it with configuration set the following in your config files:```elixir
config :azure_ad_openid, AzureADOpenId,
tenant: ,
client_id: ,
client_secret: <>, # only needed to generate access tokens
aud: <> # used to overide client_id as the value for aud
```If you don't setup the config, you will need to pass these values in manually at runtime.
For example to get the authorization url:```elixir
config = [tenant: , client_id: ]
AzureADOpenId.authorize_url!(, config)
```The following is a simple example of a Phoenix authentication controller that uses this library:
```elixir
defmodule MyAppWeb.AuthController do
use MyAppWeb, :controlleralias AzureADOpenId
def login(conn, _) do
base_uri = Application.get_env(:my_app, :base_uri)
redirect_uri = "#{base_uri}/auth/callback"
redirect conn, external: AzureADOpenId.authorize_url!(redirect_uri)
enddef callback(conn, _) do
{:ok, claims} = AzureADOpenId.handle_callback!(conn)conn
|> put_session(:user_claims, claims)
|> redirect(to: "/")
enddef logout(conn, _) do
conn
|> put_session(:user_claims, nil)
|> redirect(external: AzureADOpenId.logout_url())
end
end
```## Documentation
The docs can be found at
[https://hexdocs.pm/azure_ad_openid ](https://hexdocs.pm/azure_ad_openid/readme.html).## Credit
The following repository was used as a base for the AzureAD authentication:
[https://github.com/onurkucukkece/oauth_azure_activedirectory ](https://github.com/onurkucukkece/oauth_azure_activedirectory)
## License
Please see [LICENSE](https://github.com/whossname/azure_ad_openid/blob/master/LICENSE.md)
for licensing details.