aboutsummaryrefslogtreecommitdiff
path: root/test/ejabberd_oauth_mock.exs
blob: 2c1b8cf9315b54e0036fcc107de052303123d3a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	#  ejabberd_oauth mock
	######################

defmodule EjabberdOauthMock do

	@author "jsautret@process-one.net"

	def init() do
		:mnesia.start
		:mnesia.create_table(:oauth_token,
                         [ram_copies: [node],
													attributes: [:oauth_token, :us, :scope, :expire]])
	end

	def get_token(user, domain, command, expiration \\ 3600) do
		now = {megasecs, secs, _} = :os.timestamp
		expire = 1000000 * megasecs + secs + expiration
		:random.seed now
    token = to_string :random.uniform(100000000)
		
		{:ok, _} = :ejabberd_oauth.associate_access_token(token,
																											[{"resource_owner",
																												{:user, user, domain}},
																											 {"scope", [to_string command]},
																											 {"expiry_time", expire}],
																											:undefined)
		token
	end

end