<commit_before>-module (jwt_auth).

%%
%% Exports
%%
-export([verify/2]).

-define (SECRET, <<"This is a very secret secret, do not tell anyone.">>).


%% @doc Verify credential.
verify(Username, Token) ->
    case ejwt:parse_jwt(Token, ?SECRET) of
    	invalid -> {error, forbidden};
    	expired -> {error, forbidden};
		{Data} -> 
			case proplists:get_value(<<"id">>, Data) of
				Username ->
					ok;
				_ -> 
					{error, forbidden}
			end;
		Error ->
			{error, Error}
	end.

%%
%% Unit Tests
%%
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.<commit_msg>Handle admin tokens properly<commit_after>-module (jwt_auth).

%%
%% Exports
%%
-export([verify/2]).

-define (SECRET, <<"This is a very secret secret, do not tell anyone.">>).


%% @doc Verify credential.
verify(Username, Token) ->
    case ejwt:parse_jwt(Token, ?SECRET) of
    	invalid -> {error, forbidden};
    	expired -> {error, forbidden};
		{Data} -> 
			case proplists:get_value(<<"admin">>,Data) of
				true ->
					ok;
				false ->
					case proplists:get_value(<<"id">>, Data) of
						Username ->
							ok;
						_ -> 
							{error, forbidden}
					end
			end;
		Error ->
			{error, Error}
	end.

%%
%% Unit Tests
%%
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
{'fraction_non_alphanumeric': 0.18303220738413198, 'fraction_numerical': 0.0015710919088766694, 'mean_word_length': 2.8373493975903616, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460099', 'n_tokens_mistral': 547, 'n_tokens_neox': 468, 'n_words': 109}