oidc.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * OpenConnect (SSL + DTLS) VPN client
  3. *
  4. * Copyright © 2008-2015 Microsoft Corp
  5. *
  6. * Author: Alan Jowett <alan.jowett@microsoft.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * version 2.1, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. */
  17. #include <config.h>
  18. #include "openconnect-internal.h"
  19. #include <ctype.h>
  20. #include <errno.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. int set_oidc_token(struct openconnect_info *vpninfo, const char *token_str)
  24. {
  25. int ret;
  26. char *file_token = NULL;
  27. if (!token_str)
  28. return -ENOENT;
  29. switch(token_str[0]) {
  30. case '@':
  31. token_str++;
  32. /* fall through */
  33. case '/':
  34. ret = openconnect_read_file(vpninfo, token_str, &file_token);
  35. if (ret < 0)
  36. return ret;
  37. vpninfo->bearer_token = file_token;
  38. break;
  39. default:
  40. vpninfo->bearer_token = strdup(token_str);
  41. if (!vpninfo->bearer_token)
  42. return -ENOMEM;
  43. }
  44. vpninfo->token_mode = OC_TOKEN_MODE_OIDC;
  45. return 0;
  46. }