angular-oauth2 icon indicating copy to clipboard operation
angular-oauth2 copied to clipboard

TypeScript definition

Open shabith opened this issue 8 years ago • 6 comments

Hi,

It would be really nice to have a TypeScript definition for TypeScript users.

more info can be found here. https://github.com/typings/typings/issues/322

shabith avatar Jun 12 '16 17:06 shabith

@shabith PRs are welcome :)

ruipenso avatar Jun 21 '16 15:06 ruipenso

Here is a basic d.ts. I created, still waiting for the Oauth server to test the plugin out, untill then this seems like the right typing

I'm not sure if the grantPath and revokePath are required so I made the required

declare namespace angular.oauth2 {
    /*
     * IOAuth 
     */

     interface IOAuthConfig {
        baseUrl: string;
        clientId: string;
        clientSecret?: string;
        grantPath?: string;
        revokePath?: string;
    }
    interface IOAuthProvider {
        configure(params: IOAuthConfig): IOAuthConfig;
    }

    interface IData {
        username: string;
        password: string;
    }

    interface IOAuth {
        isAuthenticated(): boolean;
        getAccessToken(data: IData, options?: any): angular.IPromise<string>;
        getRefreshToken(data?: IData, options?: any): angular.IPromise<string>;
        revokeToken(data?: IData, options?: any): angular.IPromise<string>;
    }

    /*
     * IOAuthToken 
     */
    interface IOAuthTokenConfig {
        name: string;
        options: IOAuthTokenOptions;
    }

    interface IOAuthTokenOptions {
        secure: boolean;
    }

    interface IOAuthTokenProvider {
        configure(params: IOAuthTokenConfig): IOAuthTokenConfig;
    }
}

cskiwi avatar Jul 01 '16 07:07 cskiwi

this is great @cskiwi. Thanks for sharing this.

2 things to mention,

  1. grantPath and revokePath are optional.
  2. I think we need another 2 interfaces call IOAuthTokenProvider and IOAuthTokenConfig
interface IOAuthTokenConfig {
        name: string;
        options: any;
    }

interface IOAuthTokenProvider {
        configure(params:IOAuthTokenConfig): IOAuthTokenConfig;
    }

What do you think?

shabith avatar Jul 01 '16 09:07 shabith

@shabith , yep good idea I also added a options interface, so we don't need the any param (I really hate seeing a any in typescript/typings ^^ )

cskiwi avatar Jul 01 '16 09:07 cskiwi

That's good @cskiwi

shabith avatar Jul 01 '16 11:07 shabith

@shabith @cskiwi Can we have a PR with this?

ruipenso avatar Feb 03 '17 23:02 ruipenso