# getAuthCode

> The Alipay+ client SDK uses the getAuthCode API to obtain the authorization code from the MPP.

The Alipay+ client SDK uses the **getAuthCode** API to obtain the authorization code from the Mobile Payment Provider (MPP).

## Method signature

```objectivec
NS_ASSUME_NONNULL_BEGIN

@protocol MPPAlipayPlusClientCommonOAuthProtocol <NSObject>

- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler;

@end
NS_ASSUME_NONNULL_END

```

## Request parameters

| **Item** | **Type** | **Description** | **Required** |
| --- | --- | --- | --- |
| params | [MPPCommonOAuthServiceParams](ios_appendix#zrgJx) | Parameters that are required to obtain the authorization code. | M |
| completionHandler | iOS block | The callback to be invoked after the process to obtain the authorization code ends. See [completionHandler](#PDsey) for details. | M |

#### completionHandler

| **Item** | **Type** | **Description** | **Required** |
| --- | --- | --- | --- |
| result | [MPPCommonOAuthServiceResult](ios_appendix#jFKzK) | The result information that is required if the authorization is successful. | O |
| error | NSError | The error code that is required if the authorization fails. | O |

## Response parameters

N/A

## Sample

Definition of _YOUR\_OAUTH\_SERVICE\_CLASS_:

```objectivec
#import <MPPAlipayPlusClient/MPPAlipayPlusClientAPI.h>

@interface YOUR_OAUTH_SERVICE_CLASS: NSObject <MPPAlipayPlusClientCommonOAuthProtocol>
- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler;
@end

@implementation YOUR_OAUTH_SERVICE_CLASS
- (void)getAuthCode:(MPPCommonOAuthServiceParams *)params
            completionHandler:(void(^)(MPPCommonOAuthServiceResult *_Nullable result, NSError *_Nullable error))completionHandler; {

  //Obtain the authCode with the authClientId and scopes in params

  MPPCommonOAuthServiceResult *result = MPPCommonOAuthServiceResult.new;
  result.authCode = @"xxx";
  result.authSuccessScopes = @[@'auth_base'];
  result.authErrorScopes = [NSMutableDictionary dictionary];
  completionHandler(result, nil);

  }
@end
```

Instance of _YOUR\_OAUTH\_SERVICE\_CLASS_:

```objectivec
#import <MPPAlipayPlusClient/MPPAlipayPlusClientAPI.h>
[AlipayPlusClient shared].commonOAuthService = YOUR_OAUTH_SERVICE_CLASS.new
```