A implementation of an OAuth2 backend with
persistence on MongoDB
made with
mongopool.
[
{mongopool, [
{pools, [
{mypool, [
{size, 10},
{max_overflow, 30}
], [
{database, <<"mydb">>},
{hostname, dbserver},
{login, "myuser"},
{password, "mypassword"},
{w_mode, safe}
]}
]}
]},
{oauth2_mongopool, [
{pool, mypool}
]},
{oauth2, [
{backend, oauth2_backend_mongopool}
]}
]
After you configure oauth2 and
mongopool as wrote before, you can
start the backend to ensure that mongopool
is started.
application:ensure_all_started(oauth2_mongopool).
{ok, AppCtx} = oauth2_mongopool:init().
The AppCtx
is the application context used when you call oauth2
functions.
E.g. to verify the access token:
case oauth2:verify_access_token(<<mytoken>>, AppCtx) of
{ok, } -> true;
{error, _ErrType} -> false
end
$ utils/rebar3 compile
$ ./utils/rebar3 eunit