Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✍️ @Santi's Blog #81

Open
11 of 13 tasks
santi-jose opened this issue Oct 25, 2024 · 1 comment
Open
11 of 13 tasks

✍️ @Santi's Blog #81

santi-jose opened this issue Oct 25, 2024 · 1 comment

Comments

@santi-jose
Copy link

santi-jose commented Oct 25, 2024

Hi and welcome to Content Lab! Here is a self paced guide to ensure you get feedback as you publish your technical blog.

Resources:

Timeline:

📋 Blog Outline: Write your outline in the issue directly

Requirements

Questions to consider:

  • Who’s reading this? Where are they in your dev journey? What do they need to know before they can dive into this story?
  • If people could leave with just one action, what would it be?
  • Were there surprises or alternative problem solving you want to give a heads up to?

Sample Topics for your blog post

  • Creating tests for Stripe/Cicero/Twilio
  • Using Vuetify and V-cards
  • Debugging a PR test failure affecting entire codebase and creating an issue for it
  • System Design/Architecture design for caching capability
  • Implementing Text to Speech
  • Configuring secrets for APIs in codespaces
  • Building Actions for [security|community|CI| etc]

Example Outlines

What makes good documentation on open source?

  • Could this be a list? (3 pieces of documentation thats easy to check for and add to the project to add immediate value?
  • What inspired you from the Tech documentation workshop?
  • What would you help encourage other first time contributors to do?
  • Is a learning curve for everyone? And whats the balance between good documentation and too much documentation? Choice architecture
  • What is each space used for? Wiki vs Discussion vs Pages
  • How do we search and find?
    Reference: https://blackgirlbytes.dev/conquering-the-fear-of-contributing-to-open-source
    Reference issue/PR for photos
    Conclusion: Documentation is always changing, will always be needed`

To Do: when you complete the requirements, add "outline ready" label on your issue

  • Identify your topic from one of the PRs approved
  • Outlining bullet points of blog roadmap
  • Is your blog a List, Survey, or demo?
  • Which Visuals or Diagram or Code snippets will you add
  • References to resources

📰 Blog Rough draft: Format into a google doc

Questions to answer across draft

  • Why is this helpful for a reader?
  • What problem does this help them solve?
  • What kind of experience should the reader have or that you will provide so they’re up to speed
  • What larger problem is this solving?
  • Were there other ways of solving this problem - what made you choose the one that you did?
  • What were the positive tradeoffs? (Did it save time? Save hours? Was more secure?)
  • What is the best way to present the content (i.e. code snippets, graphics) ?
  • What additional resources can they provide the reader if they want more information?
  • Is there a call to action?

To do: when you complete the requirements, add "draft ready" label on your issue

  • intro paragraph
  • context of Amplify
  • paragraph on problem
  • paragrph compare your solution
  • paragraph impact your solution
  • Less than 600 words
  • Drop link to your google doc (with permissions for edits) in review issue
@santi-jose
Copy link
Author

santi-jose commented Nov 18, 2024

Login and Logout Component Implementation using the Auth0 SDK

  1. What is Authentication?
    Authentication in software development verifies a user’s identity to ensure secure access to applications. For example, logging into social media platforms like Facebook and Instagram requires credentials. This process is fundamental to modern applications as it protects both systems and users. [1]

    For organizations, authentication prevents unauthorized access to sensitive data. For users, it safeguards personal information, enabling trust in applications handling financial transactions or private data. Without authentication, digital security and trust would crumble. [2]

    However, implementing authentication can be complex, requiring careful balancing of security, user experience, and scalability. Developers must address challenges like data encryption and secure token management. Tools like Auth0 simplify this by providing ready-made authentication solutions. Auth0 enables developers to focus on building applications instead of reinventing secure login systems.

    In this guide, I’ll demonstrate how to set up Login and Logout components in a Vue SPA using the Auth0 SDK.

  2. Amplify Context
    Amplify is an open-source app that empowers users to advocate for environmental sustainability. By selecting a cause, providing their zip code, and making a donation, users can have Amplify send a letter supporting their cause to their nearest political representative. This simplifies taking actionable steps against climate change.

    Because Amplify processes sensitive data, such as donation history and campaign engagement, authentication is essential. Robust authentication ensures user data is protected, fostering trust and providing a secure experience as users support sustainability initiatives.

  3. Challenges of Authentication in Web Applications
    Implementing custom authentication in a web app is complex and time-consuming. While it offers flexibility and control over low-level details, developers must manage sensitive data, increasing the risk of errors. Questions quickly arise: How should passwords be securely stored? Should multi-factor authentication or single sign-on be included? How can the system scale with evolving company needs?

    Addressing these challenges requires expertise and resources. Without a dedicated team, custom solutions risk being inefficient or insecure. For most developers and organizations, third-party services like Auth0 provide a more scalable and reliable solution to handle authentication effectively. [3]

  4. Why Auth0?
    As previously outlined, implementing authentication poses challenges of complexity, security, and scalability. Scalability, in particular, ensures that Amplify’s authentication system can handle increased user demands and feature expansions without major overhauls. Auth0 addresses this need by providing a flexible, comprehensive solution.

    With Auth0, Amplify can easily implement features like Multi-Factor Authentication (MFA) to enhance user security or Single Sign-On (SSO) for seamless integration with partner platforms. Auth0 also includes attack protection measures, such as suspicious IP throttling, to safeguard against unauthorized access. Additionally, robust user management tools and role-based access control (RBAC) allow Amplify to adapt to an expanding user base and evolving access requirements.

    By leveraging Auth0’s scalable infrastructure, Amplify’s team can focus on empowering environmental advocacy while ensuring a secure, seamless user experience. [4][5]

  5. Implementing Login and Logout with Auth0 SDK
    To follow this guide, you will need:

  • An existing Vue SPA where you’ll implement login and logout functionality
  • An Auth0 account (you can sign up here)

Step 1: Create an Auth0 Application

  1. Log in to the Auth0 dashboard.
  2. Navigate to the Applications tab in the sidebar
  3. Click on Create Application, and choose the Single Page Application (SPA) option
  4. Name your application and save it

Step 2: Retrieve Application Keys

  1. Go to the Settings tab of your new SPA application
  2. Locate the Domain and ClientID keys. These keys will allow your Vue app to connect with Auth0

Step 3: Configure Environment Variables
To keep these keys secure:

  1. Create a .env file in the root of your project
  2. Add the following lines, replacing <yourDomainKeyHere> and <yourCliendIDKeyHere> with your actual keys:
VUE_APP_AUTH0_DOMAIN=<yourDomainKeyHere>
VUE_APP_AUTH0_CLIENTID=<yourClientIDKeyHere>
  1. Add .env to your .gitignore file to ensure it’s not tracked by version control

Note: Environment variables allow sensitive information to remain hidden. This keeps your application secure during development.

Step 4: Configure Callback, Logout, and Allowed Web Origin URLs
What are these URLS?

  1. Callback URL: The URL where Auth0 redirects users after a successful login. This is essential for ensuring the app can recognize authenticated users
  2. Logout URL: The URL where Auth0 redirects users after they log out of the application
  3. Allowed Web Origins: Defines which URLs can silently refresh authentication tokens, ensuring users stay logged in when refreshing or revisiting the app

Configuring URLS in Auth0

  1. Navigate to the Settings tab of your Auth0 application in the dashboard
  2. Locate the fields for Callback URL, Logout URL, and Allowed Web Origins
  3. Enter the URL where your application runs. For local development, this is typically http://localhost/:<yourPort>
  4. Save your changes

Step 5: Install the Auth0 Vue SDK

  1. Open your terminal and navigate to the root folder of your project
  2. Run the following command to install the Auth0 Vue SDK
    Npm install @auth0/auth0-vue

Step 6: Register the Auth0 Plugin:
In your main Vue file (e.g. main.js) register the Auth0 plugin:

import { createApp } from 'vue';
import { createAuth0 } from '@auth0/auth0-vue';
import App from './App.vue';

const app = createApp(App);

app.use(
  createAuth0({
    domain: import.meta.env.VUE_APP_AUTH0_DOMAIN,
    clientId: import.meta.env.VUE_APP_AUTH0_CLIENTID,
    authorizationParams: {
      redirect_uri: window.location.origin,
    },
  })
);

app.mount('#app');

Step 7: Create Login and Logout Components
Login Component

<template>
  <button @click="login">Log in</button>
</template>

<script>
    import { useAuth0 } from '@auth0/auth0-vue';

    export default {
      setup() {
        const { loginWithRedirect } = useAuth0();

        return {
          login: () => loginWithRedirect(),
        };
      },
    };
</script>

Logout Component

<template>
  <button @click="logout">Log out</button>
</template>

<script>
import { useAuth0 } from '@auth0/auth0-vue';

export default {
  setup() {
    const { logout } = useAuth0();

    return {
      logout: () =>
        logout({ logoutParams: { returnTo: window.location.origin } }),
    };
  },
};
</script>

Step 8: Add Conditional Rendering for Authentication
To toggle between Login and Logout buttons based on the user’s authentication state:

<template>
  <div class="nav-bar__buttons">
    <template v-if="!isAuthenticated">
      <Login />
    </template>
    <template v-else>
      <Logout />
    </template>
  </div>
  <h1>Welcome to the Vue SPA Auth0 Login/Logout Demo</h1>
</template>

<script setup>
import { useAuth0 } from '@auth0/auth0-vue';

const { isAuthenticated } = useAuth0();
</script>

The isAuthenticated property from the Auth0 Vue SDK determines the user’s authentication state.

Final Step: Run your Application
Start your development server and test the Login and Logout functionality. You should see the buttons toggle based on the user’s authentication state.

  1. Conclusion
    Implementing authentication in your Vue application with Auth0 can seem daunting at first, but breaking it down into manageable steps makes it straightforward. By configuring your Auth0 application, securely managing environment variables, and integrating the Auth0 Vue SDK, you can seamlessly add login and logout functionality to your app. This guide covered everything from setup to conditional rendering, ensuring a secure and user-friendly authentication experience.

    With these steps, your Vue SPA is now equipped to handle user authentication efficiently, paving the way for building scalable and secure applications. Happy coding!

References

  1. https://auth0.com/intro-to-iam/what-is-authentication
  2. https://www.microsoft.com/en-us/security/business/security-101/what-is-authentication
  3. https://fusionauth.io/articles/authentication/common-authentication-implementation-risks
  4. https://auth0.com/docs/get-started/identity-fundamentals/introduction-to-auth0
  5. https://auth0.com/docs/get-started/identity-fundamentals/identity-and-access-management
  6. https://auth0.com/docs/quickstart/spa/vuejs/01-login#configure-logout-urls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants