Beispiel #1
0
        public static OauthProvider CreateGoogleGmailApiProvider(string clientId, string clientSecret, string redirectUri)
        {
            OauthProvider provider = new OauthProvider();
            provider.AuthUri = "https://accounts.google.com/o/oauth2/v2/auth";
            provider.TokenUri = "https://www.googleapis.com/oauth2/v4/token";
            provider.RedirectUri = redirectUri;

            provider.ClientId = clientId;
            provider.ClientSecret = clientSecret;
            provider.Scope = "email%20profile%20https://www.googleapis.com/auth/gmail.send";
            provider.Prompt = "login";

            provider.UseClientSecretInRequest = true;
            provider.ParseAuthorizationCodeInHtml = true;
            provider.ProviderType = GoogleGmailApiProvider;
            return provider;
        }
Beispiel #2
0
        /*
         * Do not use our test client_id, client_secret in your production environment, you should create your client_id/client_secret for your application.
         */

        /*
         * To use Google OAUTH in your application, you must create a project in Google Developers Console.
         *
         * - Create your project at https://console.developers.google.com/project.
         * - Select your project -> APIs & Services -> Dashboard -> Credentials;
         * - Credentials -> Create Credentials -> OAuth client ID -> Web application or Other (Desktop Application).
         * It depends on your application type.
         *
         * - Input a name for your application, input your current ASP/ASP.NET URL at Authorized redirect URIs,
         * for example: http://localhost/gmailoauth/default.aspx. (Desktop Application doesn't require this step)
         * Click "Create", you will get your client id and client secret.
         *
         * - Finally you can also set detail information for your project at Credentials -> OAuth consent screen.
         *
         * - If you used https://mail.google.com , email, profile scope, you should verify your application that is inroduced in cosent screen.
         * If you don't verify your application, your application is limited by some conditions.
         *
         * You must apply for your client id and client secret, don't use the client id in the sample project, because it is limited now.
         * If you got "This app isn't verified" information, please click "advanced" -> Go to ... for test.
         */
        public static OauthProvider CreateGoogleProvider(string clientId, string clientSecret)
        {
            OauthProvider provider = new OauthProvider();

            provider.AuthUri     = "https://accounts.google.com/o/oauth2/v2/auth";
            provider.TokenUri    = "https://www.googleapis.com/oauth2/v4/token";
            provider.RedirectUri = "urn:ietf:wg:oauth:2.0:oob";

            provider.ClientId     = clientId;
            provider.ClientSecret = clientSecret;
            provider.Scope        = "email%20profile%20https://mail.google.com";
            provider.Prompt       = "login";

            provider.UseClientSecretInRequest     = true;
            provider.ParseAuthorizationCodeInHtml = true;

            return(provider);
        }
Beispiel #3
0
        /*
         * To use Microsoft OAUTH in your application, you must create a project in https://portal.azure.com.
         *
         * - Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
         * - If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the Azure AD tenant that you want.
         * - In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations > New registration.
         *
         * When the Register an application page appears, enter your application's registration information:
         *
         *  - Name - Enter a meaningful application name that will be displayed to users of the app.
         *  - Supported account types - Select which accounts you would like your application to support. Because we need to support all Office 365 and LIVE SDK (hotmail, outlook personal account)
         *         select Accounts "in any organizational directory and personal Microsoft accounts"
         *
         * Redirect URI (optional) - Select the type of app you're building, Web or Public client (mobile & desktop), and then enter the redirect URI (or reply URL) for your application.
         *
         *  For web applications, provide the base URL of your app. For example, http://localhost:31544 might be the URL for a web app running on your local machine.
         *    Users would use this URL to sign in to a web client application.
         *  For public client applications, provide the URI used by Azure AD to return token responses. Enter a value specific to your application, such as myapp://auth.
         *
         *
         * - When finished, select Register.
         *
         * Azure AD assigns a unique application (client) ID to your app, and you're taken to your application's Overview page.
         * click "Certificates and secrets" -> "client secrets" and add a new client secret.
         * Important: Please store "client secret" by yourself, because it is hidden when you view it at next time.
         *
         * - API  Permission
         * Click "API Permission" -> "Add a permission" -> "Exchange" -> "Delegated Permission" -> "Check EWS.AccessAsUser.All"
         *                        -> "Add a permission" -> "Microsoft Graph" -> "Delegated Permission" -> "User.Read", "email", "offline_access", "openid" and "profile"
         *
         * - Authentication
         * Click "Authentication" ->
         *    Implicit grant: check "Access tokens" and "ID tokens"
         *    Redirect URI: input the url to get authorization code, for native desktop application, you don't have to add redirect uri.
         *
         * Mobile and desktop applications: redirect Uri, please check the following URI.
         *   https://login.microsoftonline.com/common/oauth2/nativeclient
         *   https://login.live.com/oauth20_desktop.srf (LiveSDK)
         *
         * Supported account types: please select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
         *
         * Advanced settings: please set both "Live SDK Support" and "Treat application as a public client" to "Yes"
         *
         * Above client_id and secret support both "Office365 + EWS" and "Live (hotmail, outlook personal account) + Imap4", Office365 Oauth doesn't support IMAP4, only EWS is supported.
         */
        public static OauthProvider CreateMsOffice365Provider(string clientId, string clientSecret)
        {
            OauthProvider provider = new OauthProvider();

            provider.AuthUri     = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
            provider.TokenUri    = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
            provider.RedirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient";

            provider.ClientId     = clientId;
            provider.ClientSecret = clientSecret;
            provider.Scope        = "https://outlook.office.com/EWS.AccessAsUser.All%20offline_access%20email%20openid";

            provider.UseClientSecretInRequest     = false;
            provider.ParseAuthorizationCodeInHtml = false;

            provider.Prompt = "login";

            return(provider);
        }
Beispiel #4
0
        public static OauthProvider CreateMsLiveProvider(string clientId, string clientSecret, string redirectUri)
        {
            OauthProvider provider = new OauthProvider();
            provider.AuthUri = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
            provider.TokenUri = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
            provider.RedirectUri = redirectUri;
            provider.Scope = "wl.offline_access%20wl.signin%20wl.imap%20wl.emails%20email%20openid";

            provider.ClientId = clientId;
            provider.ClientSecret = clientSecret;

            provider.UseClientSecretInRequest = true;
            provider.ParseAuthorizationCodeInHtml = false;

            provider.Prompt = "login";
            provider.ProviderType = MsLiveProvider;

            return provider;
        }
Beispiel #5
0
 public OauthDesktopWrapper(OauthProvider provider)
 {
     _provider = provider;
 }
Beispiel #6
0
 public OauthHttpWrapper(OauthProvider provider)
 {
     _provider = provider;
 }