HubIdentityElixir.HubIdentity (HubIdentityElixir v0.1.3) View Source
An Elixir Package designed to make implementing HubIdentity authentication easy and fast. In order to use this package you need to have an account with HubIdentity
Currently this is only for Hivelocity uses. If you have a commercial interest please contact the Package Manager Erin Boeger through linkedIn or Github or through Hivelocity.
Link to this section Summary
Functions
Authenticate with HubIdentity using an email and password. This will call the HubIdentity server and try to autheniticate. Use this method for users who authenticate directly with HubIdentity. Upon successful email and password
Get the current servers public key certificates. These certificates are used to verify a HubIdentity issued JWT signature. These certificates are rotated on a regular basis. If your website has significant activity, it may make sense to cache and refresh when they expire. Each certificate returned has a timestamp of when the certificate will expire.
Get a certificate by a kid. The kid is included with every HubIdentity issued JWT and idetnitifies which certificate was used to generate the certificate.
Get the list of Open Authentication Providers from HubIdentity. Remember these links are only good once, and one link. If a users authenticates with Google then the facebook link will be invalid. The links also expire with 10 minutes of issue.
Parse and validate a JWT from HubIdentity. When successful will return an ok tuple with a current_user map.
Link to this section Functions
Authenticate with HubIdentity using an email and password. This will call the HubIdentity server and try to autheniticate. Use this method for users who authenticate directly with HubIdentity. Upon successful email and password
Examples
iex> HubIdentityElixir.authenticate(%{email: "erin@hivelocity.co.jp", password: "password"})
{:ok, %{"access_token" => access_token, "refresh_token" => refresh_token}}
iex> HubIdentityElixir.authenticate(%{email: "erin@hivelocity.co.jp", password: "wrong"})
{:error, "bad request"}
Get the current servers public key certificates. These certificates are used to verify a HubIdentity issued JWT signature. These certificates are rotated on a regular basis. If your website has significant activity, it may make sense to cache and refresh when they expire. Each certificate returned has a timestamp of when the certificate will expire.
Examples
iex> HubIdentityElixir.get_certs()
[
{
"alg": "RS256",
"e": "AQAB",
"expires": 1614837416,
"kid": "C8Rn3J8tPlMp8etztCsb4k51sjTFXbA-Til9XptF2FM",
"kty": "RSA",
"n": "really long n",
"use": "sig"
},
...
]
Get a certificate by a kid. The kid is included with every HubIdentity issued JWT and idetnitifies which certificate was used to generate the certificate.
Examples
iex> HubIdentityElixir.get_certs("C8Rn3J8tPlMp8etztCsb4k51sjTFXbA-Til9XptF2FM")
{
"alg": "RS256",
"e": "AQAB",
"expires": 1614837416,
"kid": "C8Rn3J8tPlMp8etztCsb4k51sjTFXbA-Til9XptF2FM",
"kty": "RSA",
"n": "really long n",
"use": "sig"
}
iex> HubIdentityElixir.get_certs("expired or not valid kid")
nil
Get the list of Open Authentication Providers from HubIdentity. Remember these links are only good once, and one link. If a users authenticates with Google then the facebook link will be invalid. The links also expire with 10 minutes of issue.
Examples
iex> HubIdentityElixir.get_providers()
[
{
"logo_url": "https://stage-identity.hubsynch.com/images/facebook.png",
"name": "facebook",
"request_url": request_url
}
]
Parse and validate a JWT from HubIdentity. When successful will return an ok tuple with a current_user map.
Examples
iex> HubIdentityElixir.parse_token(%{"access_token" => access JWT})
{:ok, %{
owner_type: "Hubsynch.User",
owner_uid: "uid_1234",
uid: "hub_identity_uid_1234",
user_type: "HubIdentity.User"
}
}
iex> HubIdentityElixir.parse_token(%{"access_token" => invalid JWT})
{:error, :claims_parse_fail}