aboutsummaryrefslogtreecommitdiff
path: root/lib/vnlib.browser/src
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-01-06 18:06:01 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-01-06 18:06:01 -0500
commit3bd7effc15d0b87adce01281b073aa1db67d3cba (patch)
treee8fcf15b9d6664bcd48bb17ac2c71c70abda204d /lib/vnlib.browser/src
parentf4c2c9e148374f462592c19e8ffd4db14672805d (diff)
social portal conversion, pull provider libraries & include some prebuilts
Diffstat (limited to 'lib/vnlib.browser/src')
-rw-r--r--lib/vnlib.browser/src/social/index.ts25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/vnlib.browser/src/social/index.ts b/lib/vnlib.browser/src/social/index.ts
index a164eb8..121fb50 100644
--- a/lib/vnlib.browser/src/social/index.ts
+++ b/lib/vnlib.browser/src/social/index.ts
@@ -1,4 +1,4 @@
-import { find, isEqual } from "lodash-es";
+import { find, isEqual, map } from "lodash-es";
import { get } from "@vueuse/core";
import { MaybeRef } from "vue";
import Cookies from "universal-cookie";
@@ -66,6 +66,16 @@ export interface SocialLoginApi<T>{
}
/**
+ * A social OAuth portal that defines a usable server
+ * enabled authentication method
+ */
+export interface SocialOAuthPortal {
+ readonly id: string;
+ readonly login: string;
+ readonly logout: string;
+}
+
+/**
* Creates a new social login api for the given methods
*/
export const useSocialOauthLogin = <T extends OAuthMethod>(methods: T[], axiosConfig?: Partial<AxiosRequestConfig>): SocialLoginApi<T> =>{
@@ -229,4 +239,15 @@ export const createSocialMethod = (id: string, path: MaybeRef<string>): OAuthMet
Id: id,
loginUrl: () => get(path),
}
-} \ No newline at end of file
+}
+
+/**
+ * Creates social OAuth methods from the given portals (usually captured from the server)
+ */
+export const fromPortals = (portals: SocialOAuthPortal[]): OAuthMethod[] => {
+ return map(portals, p => ({
+ Id: p.id,
+ loginUrl: () => p.login,
+ getLogoutData: () => ({ url: p.logout, args: {} })
+ }))
+}